nserror

Swift idiomatic error checking

…衆ロ難τιáo~ 提交于 2019-12-17 19:07:02
问题 Let's say that you have a function like this: func getSomething(error: NSErrorPointer) -> Something and you typically use it this way: var error : NSError? = nil let a = getSomething(&error) What is an idiomatic way to check for error here? More specific questions: If error == nil can we assume that a will never be nil and vice versa? What should we check first: error (for its nilness) or a (to confirm that it's not a nil)? Can a != nil && error != nil be true in some cases? Thank you! 回答1:

NSURL Error Handling

孤者浪人 提交于 2019-12-13 12:52:19
问题 my app is supposed to make a request from a server every 10 seconds or so with a specific url, change some attributes in the url, and then show the request in another view called "updateView" or if any network error occurred display the error. The first part works fine but if i switch of wifi for example the app crashes. How do i fix this and how do i display the various errors? Thanks in advance!! Here's my code (this is the method which gets called every 10 seconds): - (void)serverUpdate{

Swift 3 custom URLProtocol crashes when converting Error to NSError

▼魔方 西西 提交于 2019-12-12 06:48:51
问题 I've got a rather large body of Swift 3 code for Mac OS 10.11 and up (using Xcode 8.2.1). There are a number of processes, among them a GUI application and a background service. Both of these use a custom URLProtocol , which is implemented in a framework (imported by both application and service). The protocol sometimes may generate instances of an enum that conforms to Error , which it catches and handles appropriately (generally by using the URLProtocolClient to toss them up to the

How do I get at the underlying Error from an Alamofire error?

不想你离开。 提交于 2019-12-11 00:51:41
问题 For this request: Alamofire.request("https://google.com").responseCollection { (response: DataResponse<[User]>) in guard response.result.isSuccess else { print(response.error) return } } I see this printed in the console: Optional(my_app_name.BackendError.jsonSerialization(Alamofire.AFError.responseSerializationFailed(Alamofire.AFError.ResponseSerializationFailureReason.jsonSerializationFailed(Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 0." UserInfo=

NSURLErrorDomain Code=-1012 The operation couldn’t be completed

ぐ巨炮叔叔 提交于 2019-12-10 14:37:57
问题 I am getting the following error when running my code from the xcode. Error Domain=NSURLErrorDomain Code=-1012 "The operation couldn’t be completed. (NSURLErrorDomain error -1012.)" UserInfo=0x17166b740 {NSErrorFailingURLStringKey= https://..../move/resource/v1/user/me/activity/summary?start_date=2015-01-21&end_date=2015-01-14&detail=true , NSUnderlyingError=0x17405b630 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1012.)", NSErrorFailingURLKey= https://..../move

Swift 3.1: Crash when custom error is converted to NSError to access its domain property

放肆的年华 提交于 2019-12-10 13:45:56
问题 My Swift app has a custom error system where MyError is just a simple class conforming to Error . Now the app seems to crash whenever a third-party library (PromiseKit) tries to convert this error to NSError and then to access its domain property. In my own code, doing this works as expected, so why does it crash in the library and what's the proper way of dealing with it? Crashed: com.apple.main-thread 0 libswiftCore.dylib 0x1011d86d8 _hidden#19226_ (__hidden#19178_:1788) 1 libswiftCore

SSErrorDomain, SKReceiptRefreshRequest, SKRequest did fail with error, code = 16, code = 110

与世无争的帅哥 提交于 2019-12-09 11:37:00
问题 iOS 9.2.1, Xcode 7.2.1, ARC enabled I am using the following method to check for failures of SKProductsRequest and SKReceiptRefreshRequest : - (void)request:(SKRequest *)request didFailWithError:(NSError *)error { NSLog(@"error: %@", error); } My question is specifically about SKReceiptRefreshRequest . I am testing for two conditions, (1) when the user cancels the sign-in to iTunes Store for the receipt request and (2) when the user tries to sign-in and there is no connection (Air Plane Mode)

What's the difference between Error and NSError in Swift?

雨燕双飞 提交于 2019-12-09 04:19:47
问题 I am creating a library that should return errors so I'm wondering which one should use for my purposes. UPDATE: I should clarify, the returned result will be from a asynchronous call so I need to inform to the user if there was an error and I would like to know which type I should use Error or NSError. 回答1: NSError is a Cocoa class An NSError object encapsulates information about an error condition in an extendable, object-oriented manner. It consists of a predefined error domain, a domain

unexpectedly found nil while unwrapping an Optional value with AVAudioPlayer

耗尽温柔 提交于 2019-12-08 09:38:16
问题 So this code runs fine on the iOS Simulators, but not on my iPad Mini var sound = NSURL(fileURLWithPath:"/Users/Dan/Documents/XCode Code/Colors- Tabbed?/Colors- Tabbed?/Sweg.aiff") var audioPlayer = AVAudioPlayer() audioPlayer = AVAudioPlayer(contentsOfURL: sound, error: &error) var error: NSError? I get the error "unexpectedly found nil while unwrapping an Optional value" on the last line. 回答1: It looks like AVAudioPlayer hasn't been audited yet. It returns an implicitly unwrapped optional,

Best way to handle errors from async closures in Swift 2?

廉价感情. 提交于 2019-12-07 03:14:54
问题 I'm using a lot of async network request (btw any network request in iOS need to by async) and I'm finding way to better handle errors from Apple's dataTaskWithRequest which not supports throws . I have code like that: func sendRequest(someData: MyCustomClass?, completion: (response: NSData?) -> ()) { let request = NSURLRequest(URL: NSURL(string: "http://google.com")!) if someData == nil { // throw my custom error } let task = NSURLSession.sharedSession().dataTaskWithRequest(request) { data,