我必须做些错事,因为在NSDictionary
中,值是1或0,它总是打印"locked"
。。。
let object: NSDictionary = self.collectionObjects?.objectAtIndex(indexPath.row) as! NSDictionary
if let locked = (object.objectForKey("locked") as? NSNumber)?.boolValue {
println("locked")
} else {
println("open")
}
最佳答案
你没有在那里测试任何东西
尝试,
let object: NSDictionary = self.collectionObjects?.objectAtIndex(indexPath.row) as! NSDictionary
let locked = (object.objectForKey("locked") as? NSNumber)?.boolValue
if locked == true
{
println("locked")
}
else
{
println("open")
}
关于ios - if语句 swift 忽略 bool 值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32483086/