问题描述
我在SO上看过类似的问题,但实际上没有人能回答这个问题。 Swift编程语言一书(v.1.2)说:
I've seen similar questions on SO, but none actually has the answer to this question. "The Swift Programming Language" book (v. 1.2) says:
然后在下一页上他们有以下示例(为了简洁起见,我删除了一些代码):
And then on the next page they have the following example (I got rid of some code for the sake of brevity):
class SomeClass {
static var storedTypeProperty = "Some value."
// ...
}
即使变量名称也说明了存储的类型属性(不是计算的属性)。
Even the name of variable says it's a stored type property (not a computed one).
更新:您可以定义类的存储属性,请参阅下面的详细解答。原来这本书没有更新Swift 1.2中的这一部分。
Update: You can define stored properties for classes, see the detailed answer below. Turned out the book wasn't updated with the changes in Swift 1.2 for this part.
推荐答案
引入了类中的静态存储属性 Swift 1.2 。
列表(重点补充):
Static stored properties in classes were introduced with Swift 1.2.The Xcode 6.3 Release Notes list under Swift Language Enhancements (emphasis added):
示例
class SomeClass {
static var storedTypeProperty = "Some value."
// ...
}
是静态属性的示例一堂课。
语句
is an example for a static property of a class.The statement
不正确,根据此语言更改尚未更新。
is not correct, it has not yet been updated according to this language change.
这篇关于Swift中类的存储类型属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!