纠正这两个条件if语句的正确方法是什么?
我收到一个编译器错误,内容为 could not find an overload for '==' that accepts the supplied arguments
如果我只使用其中一个,那很好,但是当我添加另一个时,它是行不通的。
for item in imageOutlets {
if collectionObjects.count > 0 {
let imageObject = self.collectionObjects.objectAtIndex(count) as! PFObject
let imageFile = imageObject.objectForKey(smallThumbImage) as! PFFile
imageFile.getDataInBackgroundWithBlock({ (data, error) -> Void in
if (error == nil) || (imageFile != nil) {
item.image = UIImage(data: data!)
} else {
item.image = UIImage(named: "placeholder")
println("error loading image")
}
只有Optional变量可以为nil,因此将代码更改为此
let imageFile = imageObject.objectForKey(smallThumbImage) as? PFFile
imageFile?.getDataInBackgroundWithBlock({(data: NSData!, error: NSError!) -> Void in
if (error == nil){ //here do not need to check imageFile
item.image = UIImage(data: data!)
} else {
item.image = UIImage(named: "placeholder")
println("error loading image")
}
})
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句