我非常确定.count
会返回数组的长度,但出于某种原因,当我使用它时,它会引发一个奇怪的错误。
继承我的代码:
let dataFile = NSBundle.mainBundle().pathForResource(RopeDataFile, ofType: nil)
let ropes = NSArray(contentsOfFile: dataFile!);
for i in 0..<ropes.count {
}
RopeDataFile
是我之前制作的属性列表的常量。
出于某种原因,它会在ropes.count
,
&#39; NSArray的&#39?;没有名为&#39; count&#39;。
的成员
如果问题非常简单,我很快就会感到很抱歉。
答案 0 :(得分:6)
NSArray(contentsOfFile: dataFile!)
会返回可选数组。所以你必须使用像
ropes?.count
或者您可以先打开ropes
数组
if let array = ropes{
for i in 0..< array.count {
}
}
答案 1 :(得分:1)
ropes!.count
使用!
NSArray(contentsOfFile: dataFile!) return an optional array