草庐IT

swift 、NSJSONSerialization 和 NSError

问题是当数据不完整时,NSJSONSerialization.JSONObjectWithData会导致应用程序崩溃,并给出unexpectedlyfoundnilwhileunwrappinganOptionalvalue错误,而不是使用NSError变量通知我们。所以我们无法防止崩溃。您可以在下面找到我们正在使用的代码varerror:NSError?=nilletdataToUse=NSJSONSerialization.JSONObjectWithData(receivedData,options:NSJSONReadingOptions.AllowFragments,erro

swift 、NSJSONSerialization 和 NSError

问题是当数据不完整时,NSJSONSerialization.JSONObjectWithData会导致应用程序崩溃,并给出unexpectedlyfoundnilwhileunwrappinganOptionalvalue错误,而不是使用NSError变量通知我们。所以我们无法防止崩溃。您可以在下面找到我们正在使用的代码varerror:NSError?=nilletdataToUse=NSJSONSerialization.JSONObjectWithData(receivedData,options:NSJSONReadingOptions.AllowFragments,erro

ios - xcode 8 类型 'Error' 的值没有成员 'userinfo'

我刚刚升级到Xcode8,并且已经收到导致构建失败的错误。我是swift的新手,请帮忙。我应该将其更改为什么?谢谢更新除此错误外,我还得到以下信息:PFUser.logInWithUsername(inBackground:usernameTextField.text!,password:passwordTextField.text!,block:{(user,error)->Voidin//self.activityIndicator.stopAnimating()UIApplication.shared.endIgnoringInteractionEvents()ifuser!=n

ios - xcode 8 类型 'Error' 的值没有成员 'userinfo'

我刚刚升级到Xcode8,并且已经收到导致构建失败的错误。我是swift的新手,请帮忙。我应该将其更改为什么?谢谢更新除此错误外,我还得到以下信息:PFUser.logInWithUsername(inBackground:usernameTextField.text!,password:passwordTextField.text!,block:{(user,error)->Voidin//self.activityIndicator.stopAnimating()UIApplication.shared.endIgnoringInteractionEvents()ifuser!=n

ios - Swift 不会将 Objective-C NSError** 转换为抛出

我有一些Objective-C遗留代码,声明方法如下-(void)doSomethingWithArgument:(ArgType)argumenterror:(NSError**)error写在这里https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/AdoptingCocoaDesignPatterns.htmlSwiftautomaticallytranslatesObjective-Cmethodsthatproduceerrorsintomethodst

ios - Swift 不会将 Objective-C NSError** 转换为抛出

我有一些Objective-C遗留代码,声明方法如下-(void)doSomethingWithArgument:(ArgType)argumenterror:(NSError**)error写在这里https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/AdoptingCocoaDesignPatterns.htmlSwiftautomaticallytranslatesObjective-Cmethodsthatproduceerrorsintomethodst

ios - 从 (_,_,_) 类型的抛出函数 throws -> Void 到非抛出函数类型 (NSData?, NSURLResponse?, NSError?) -> Void 的无效转换

我写了这段代码:funcgetjson(){leturlPath="https://api.whitehouse.gov/v1/petitions.json?limit=100"leturl=NSURL(string:urlPath)letsession=NSURLSession.sharedSession()lettask=session.dataTaskWithURL(url!,completionHandler:{data,response,error->Voidinprint("Taskcompleted")if(error!=nil){print(error!.localiz

ios - 从 (_,_,_) 类型的抛出函数 throws -> Void 到非抛出函数类型 (NSData?, NSURLResponse?, NSError?) -> Void 的无效转换

我写了这段代码:funcgetjson(){leturlPath="https://api.whitehouse.gov/v1/petitions.json?limit=100"leturl=NSURL(string:urlPath)letsession=NSURLSession.sharedSession()lettask=session.dataTaskWithURL(url!,completionHandler:{data,response,error->Voidinprint("Taskcompleted")if(error!=nil){print(error!.localiz

ios - Swift 创建 NSError 对象

我正在尝试创建一个错误对象以显示给用户。letuserInfo:[NSObject:AnyObject]=["NSLocalizedDescriptionKey":NSLocalizedString("Unauthorized",comment:""),"NSLocalizedFailureReasonErrorKey":NSLocalizedString("Unauthorized",comment:"")]leterr=NSError(domain:"ShiploopHttpResponseErrorDomain",code:httpResponse.statusCode,user

ios - Swift 创建 NSError 对象

我正在尝试创建一个错误对象以显示给用户。letuserInfo:[NSObject:AnyObject]=["NSLocalizedDescriptionKey":NSLocalizedString("Unauthorized",comment:""),"NSLocalizedFailureReasonErrorKey":NSLocalizedString("Unauthorized",comment:"")]leterr=NSError(domain:"ShiploopHttpResponseErrorDomain",code:httpResponse.statusCode,user