gpt4 book ai didi

swift - 学习类型方法/类型属性

转载 作者:可可西里 更新时间:2023-11-01 02:18:17 26 4
gpt4 key购买 nike

我正在通读有关类型方法和类型属性的 Swift 文档,但我终究无法弄清楚为什么它会这样说(粗体):

Within the body of a type method, the implicit self property refers to the type itself, rather than an instance of that type. For structures and enumerations, this means that you can use self to disambiguate between type properties and type method parameters, just as you do for instance properties and instance method parameters.

More generally, any unqualified method and property names that you use within the body of a type method will refer to other type-level methods and properties. A type method can call another type method with the other method’s name, without needing to prefix it with the type name. Similarly, type methods on structures and enumerations can access type properties by using the type property’s name without a type name prefix.

那么,为什么这指出结构和枚举能够做这些事情,据我所知,你可以用任何类型的方法/参数(即类还有)?这让我觉得我错过了什么。

我正在查看的文档中的页面在这里:https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Methods.html

最佳答案

显然我不是唯一有这个问题的人。我不确定我以前怎么没看到这篇文章:https://softwareengineering.stackexchange.com/questions/276962/static-properties-and-implicit-self-property-in-structures-and-enumerations-vs

关于swift - 学习类型方法/类型属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34368247/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com