正确的发音方式!
是“我发誓要学习程序。” 因为那就是你在做什么。为什么觉得自己必须使用!
?使用guard-let
工作一切为你:
let task = NSURLSession.sharedSession().dataTaskWithRequest(request) { data, response, error in guard error == nil else { print("Error: \(error)") return } guard let data = data else { fatalError("error was nil, but no data. This should never happen") } guard let responseString = NSString(data: data, encoding: NSUTF8StringEncoding) else { print("Couldn't decode data") return } dispatch_async(dispatch_get_main_queue()) { self.testLabel.text = "\(responseString)" } }