2016-02-05 11 views
0

Swift Errors Thrown from here are not handled錯誤從這裏扔進沒有處理,因爲封閉的缺點是沒有窮盡

我跟着上面的鏈接,但我仍然看到這個問題。下面

do { 
    // print("\(v)") 
    let jsonData = try NSJSONSerialization.dataWithJSONObject(["code":"102", "response":v], options: NSJSONWritingOptions.PrettyPrinted) 
    let string: String! = String(data: jsonData, encoding: NSUTF8StringEncoding); 
    print("\(string)") 
    BonjourClient.sharedInstance.sendString(string) 
} 
catch let error as NSError { 
    print(error) 
} 
+0

什麼版本的Xcode您使用的是?我曾經在舊版本中看到過這種情況(因爲編譯器沒有意識到dataWithJSONObject只會拋出NSErrors),但我無法用7.2重現它。 –

+0

嗨@RobNapier Xcode我正在使用的版本是7.2。 – Audi

+0

問題是有可能拋出不是「NSError」的錯誤,而你沒有處理這些錯誤。我很驚訝我沒有看到這個錯誤,至少在操場上。 (我在本週早些時候注意到,我沒有在代碼中看到這個錯誤,這讓我感到吃驚。) –

回答

0

問題添加的代碼是你缺少一個空的漁獲物,並應該加上:


catch { 
} 
相關問題