Agg*_*sor 2 ios swift optional-chaining
这是不允许的(坏表达)
if !(let nsDictionaryObject = swiftObject as? NSDictionary)
{
"Error could not make NSDictionary in \(self)"
return
}
Run Code Online (Sandbox Code Playgroud)
是否可以在1行中检查可选链表达式的否定值?
在Swift 2.0中,您可以使用
guard let nsDictionaryObject = swiftObject as? NSDictionary else {
"Error could not make NSDictionary in \(self)"
return
}
Run Code Online (Sandbox Code Playgroud)
这也将绑定nsDictionaryObject到guard语句之外的范围.
| 归档时间: |
|
| 查看次数: |
383 次 |
| 最近记录: |