我不知道原因,但我无法检查 UIImage 是否为 nil
,即代码
var arrayBuildingImage: [UIImage] = []
for(var i = 0; i <= 100; i++){
var path:String = self.getDocumentsDirectory().stringByAppendingPathComponent("building/\(i).png")
if ( arrayBuildingImage[i] = UIImage(contentsOfFile: path)? ) {//ERROR HERE
}
else{
break
}
}
错误:
Type() 不符合协议(protocol)'BooleanType'
我正在使用 Swift 1.1
最佳答案
你应该检查它是否为零:
let img : UIImage? = UIImage(contentsOfFile: path)
if img != nil {}
或者使用“if let”语句:
if let img = UIImage(contentsOfFile: path) {}
以一种更“敏捷”的方式:
guard let img = UIImage(contentsOfFile: path) else { return }
// Do you stuff here
关于ios - type()不符合协议(protocol),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34038291/