不,这不是尝试和捕获的目的.!意思是"如果这是零,那么崩溃." 如果你不是那个意思,那么就不要使用!(提示:你很少想使用!).使用if-let或guard-let:
if let url = NSURL(string: urlString) {
UIApplication.sharedApplication().openURL(url)
}
Run Code Online (Sandbox Code Playgroud)
如果你已经有一个try区块并希望将这种情况转变为a throw,那么这guard-let是理想的:
guard let url = NSURL(string: urlString) else { throw ...your-error... }
// For the rest of this scope, you can use url normally
UIApplication.sharedApplication().openURL(url)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1417 次 |
| 最近记录: |