【发布时间】:2016-07-16 06:38:48
【问题描述】:
下面是在实例方法中直接使用静态成员:
public struct RankSet {
private let rankSet : UInt8
static let counts : [UInt8] = [
0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
... // More of the same
4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8
]
public var count : Int {
get {
// The error is on the following line
return Int(counts[Int(rankSet)])
}
}
}
Swift 产生以下错误:
静态成员
'counts'不能用于'RankSet'类型的实例
由于静态成员在我的类的所有实例之间共享,所有实例成员,包括count,都应该有权访问counts 成员。这是怎么回事?
【问题讨论】:
标签: swift static compiler-errors