【发布时间】:2015-12-21 20:56:26
【问题描述】:
我在 Swift 1.2 中非常使用这种方法:NSURLConnection.sendSynchronousRequest(:_:_:_),但这在 iOS9 中显然已被弃用。但是它仍然有效,但现在它使用新的 Swift 2.0 错误处理,我不知道如果它失败了我将如何得到错误消息,例如。如果时间用完了。
我知道我必须将它放入一个 do-catch 中,然后在方法之前说 try 但我不知道如何捕获错误消息。
do {
let data = try NSURLConnection.sendSynchronousRequest(request, returningResponse: nil)
return data
}
catch _ {
return nil
}
之前我用过 NSError 和它的 description 属性,但现在我不知道了。
【问题讨论】:
标签: ios swift error-handling try-catch swift2