ios - 数组?没有名为 "Generator"的成员

标签 ios swift nsarray

我从这段代码中得到了一个奇怪的错误:

let path = NSBundle.mainBundle().pathForResource("SampleData", ofType: "plist")

let dataArray = NSArray(contentsOfFile: path!)

for dict: AnyObject in dataArray{ ...}

最佳答案

NS数组?不是 NSArray。它是一个可选的 NSArray,换句话说,要么是一个 NSArray,要么什么都不是。

要么写

for dict: AnyObject in dataArray!

如果 dataArray 为 nil 或写入,它将工作或崩溃

if let dataArray = NSArray (contentsOfFile: path!)
{
    ...
}

关于ios - 数组?没有名为 "Generator"的成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30970534/

相关文章:

iOS UIWebView : How can I figure out what the previous URL is?

json - 尝试使用 Swift 中的 Json token 从服务器获取身份验证

arrays - 获取相同键的值

iphone - 数组中的对象数组通过测试

iphone - 使用 iOS 5 的外观 API 自定义 UIButton 的 titleLabel

javascript - 如何使用 React Native 使工具栏位于默认键盘上方?

ios - 使用 NSPredicate 过滤 NSArray 并找到相似的字符串

swift - 为什么我得到 “' UIView'没有名为 'image'的成员,我该如何解决?

iphone - 我如何检查 NSArray 中是否存在特定的 NSString?

cocoa - Objective-C/cocoa 丢失数组值