nserror

NSError domains / custom domains - conventions and best practices

梦想的初衷 提交于 2019-11-30 06:49:39
NSError requires a domain, which I understand segments the range of error codes. One would anticipate that there exist somewhere a registry of domain.error code but I've not been able to discover one. Supposedly this could used for looking up localized descriptions for errors. Does anyone have any set of known best practices for dealing with error domains and codes? An authoritative reference (major developers or framework makers) is optimal, but even blogs detailing a good convention is useful. In your projects do you maintain registries of your error domains/codes that map to localized

Swift doesn't convert Objective-C NSError** to throws

喜夏-厌秋 提交于 2019-11-30 06:46:52
问题 I have some Objective-C legacy code, that declares method like - (void)doSomethingWithArgument:(ArgType)argument error:(NSError **)error As written here https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/AdoptingCocoaDesignPatterns.html Swift automatically translates Objective-C methods that produce errors into methods that throw an error according to Swift’s native error handling functionality. But in my project described methods are called like this:

Cannot understand NSError/NSObject pointer passing behavior

随声附和 提交于 2019-11-30 05:14:59
问题 I am now confused by pointer to pointer even though I've read Why does NSError need double indirection? (pointer to a pointer) and NSError * vs NSError ** and much more. I've done some thinking and still got some questions. Here I wrote this: NSError *error = [NSError errorWithDomain:@"before" code:0 userInfo:nil]; NSLog(@"outside error address: %p", &error]; [self doSomethingWithObj:nil error:&error]; In order to test the above NSError method, I wrote this: - (id)doSomethingWithObj:(NSObject

How to detect and handle HTTP error codes in UIWebView?

半城伤御伤魂 提交于 2019-11-30 04:53:14
I want to inform user when HTTP error 404 etc is received. How can I detect that? I've already tried to implement - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error but it is not called when I receive 404 error. You could capture the URLRequest here: - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType and hand the request over to the delegate and return no. Then in the received response call from NSURLConnection cancel the connection and if everything is fine (check response) load

Returning errors in objective-c

馋奶兔 提交于 2019-11-30 02:46:07
问题 Im newish to objective-c and am starting to wonder what is the common/standard/proper way for handling and catching errors? It seems like it might be possible to use NSError to do this, is that a good idea or a hijack of cocoa? 回答1: I'm pretty sure that's what the NSError class is there to do - give details about errors. The most common pattern you'll see is a method that takes a pointer to an NSError object, as in: - (id)doSomethingWithArgument:(id)arg error:(NSError **)error The method

Best Practice - NSError domains and codes for your own project/app

倾然丶 夕夏残阳落幕 提交于 2019-11-29 18:46:28
There is a previous SO post regarding setting up error domains for your own frameworks, but what is the best practice regarding setting up error domains and custom error codes for your own project/app ? For example, supposing you're working on a Core Data-intensive app with lots of validations, should you just stick with the "off the shelf" Core Data error codes (such as NSManagedObjectValidationError from CoreDataErrors.h ) or should you create your own MyAppErrors.h and define errors with more specificity (i.e., MyAppValidationErrorInvalidCombinationOfLimbs ? Creating a custom error domain

Setting NSError within a block, using ARC

眉间皱痕 提交于 2019-11-29 08:16:01
问题 I wish to set an NSError pointer from within a block in a project using automatic reference counting. What follows is a simplified version of my code: - (BOOL)frobnicateReturningError:(NSError **)error { NSArray *items = [NSArray arrayWithObjects:@"One", @"Two", @"Three", nil]; __block Frobnicator *blockSelf = self; [items enumerateObjectsUsingBlock:^(id item, NSUInteger idx, BOOL *stop) { [blockSelf doSomethingWithItem:item error:error]; }]; } This compiles but given error may be modified by

why is “error:&error” used here (objective-c)

╄→尐↘猪︶ㄣ 提交于 2019-11-29 04:27:25
why is "error:&error" used here (objective-c) NSError *error = nil; NSArray *array = [moc executeFetchRequest:request error:&error]; wouldn't an object in objective-c be effectively pass-by-reference anyway? The argument type for error: is NSError** (i.e. a pointer to a pointer to an object). This permits the moc object to allocate and initialize a new NSError object as required. It is a common pattern, especially in Cocoa. The NSError documentation gives some indication of the motivation for this approach: Applications may choose to create subclasses of NSError to provide better localized

Swift: Corelocation handling NSError in didFailWithError

青春壹個敷衍的年華 提交于 2019-11-29 03:36:43
I'm using CoreLocation to successfully determine the user's location. However when i try to use the CLLocationManagerDelegate method: func locationManager(_ manager: CLLocationManager!, didFailWithError error: NSError!) I run into problems with the error term. func locationManager(manager: CLLocationManager!, didFailWithError error: NSError!) { println("didFailWithError \(error)") if let err = error { if err.code == kCLErrorLocationUnknown { return } } } This results in a 'Use of unresolved identifier kCLErrorLocationUnknown' error message. I know that the kCLErrors are enums and that they

How to detect and handle HTTP error codes in UIWebView?

喜你入骨 提交于 2019-11-29 02:51:11
问题 I want to inform user when HTTP error 404 etc is received. How can I detect that? I've already tried to implement - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error but it is not called when I receive 404 error. 回答1: You could capture the URLRequest here: - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType and hand the request over to the delegate and return no. Then in the