我知道这会很基础,但是我有这段代码:
var labels: [String]?
func initVC(image: Images){
self.image = image
let tempLabels = image.label?.allObjects as! [Labels]
for i in 0..<tempLabels.count{
labels?.append(tempLabels[i].label!)
}
}
labels在公共作用域中,因此函数应该可以访问它,但是当循环运行时,labels仍然为nil,没有任何元素。
当我在调试过程中使用po命令时,tempLabels像我预期的那样有两个字符串元素。
我相信这是一个非常简单的问题,但我想我现在有点迷糊了。