nserror

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

假装没事ソ 提交于 2019-11-29 01:18:38
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: object.doSomething(argument: ArgType, error: NSErrorPointer) Moreover, it throws runtime exception when I

[__NSArrayM insertObject:atIndex:]: object cannot be nil - how determine where is the error?

梦想的初衷 提交于 2019-11-28 21:42:03
问题 I have big project with async event, and sometimes i have error [__NSArrayM insertObject:atIndex:]: object cannot be nil , but I havent idea where is throwing this error.. How can I catch this error? I make assert in everywhere where I make operation insertobject:atIndex and nothing.. This is stack: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil' *** First throw call stack: (0x34c352a3

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

十年热恋 提交于 2019-11-28 13:39:59
问题 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

Swift idiomatic error checking

自作多情 提交于 2019-11-28 09:33:09
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! Compare Handling Error Objects Returned From Methods in the "Error Handling Programming Guide": Important:

NSError: Does using nil to detect Error actually turn off error reporting?

江枫思渺然 提交于 2019-11-28 07:56:51
问题 I got into the habit of coding my error handling this way: NSError* error = nil; NSDictionary *attribs = [[NSFileManager defaultManager] removeItemAtPath:fullPath error:&error]; if (error != nil) { DLogErr(@"Unable to remove file: error %@, %@", error, [error userInfo]); return; } But looking at the documentation It seems like I got this wrong.: - (BOOL)removeItemAtPath:(NSString *)path error:(NSError **)error If an error occurs, upon return contains an NSError object that describes the

How can I use NSError in my iPhone App?

浪子不回头ぞ 提交于 2019-11-28 02:32:02
I am working on catching errors in my app, and I am looking into using NSError . I am slightly confused about how to use it, and how to populate it. Could someone provide an example on how I populate then use NSError ? Alex Well, what I usually do is have my methods that could error-out at runtime take a reference to a NSError pointer. If something does indeed go wrong in that method, I can populate the NSError reference with error data and return nil from the method. Example: - (id) endWorldHunger:(id)largeAmountsOfMonies error:(NSError**)error { // begin feeding the world's children... // it

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

眉间皱痕 提交于 2019-11-27 18:26:02
问题 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? 回答1: 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

How can I use NSError in my iPhone App?

瘦欲@ 提交于 2019-11-26 23:45:03
问题 I am working on catching errors in my app, and I am looking into using NSError . I am slightly confused about how to use it, and how to populate it. Could someone provide an example on how I populate then use NSError ? 回答1: Well, what I usually do is have my methods that could error-out at runtime take a reference to a NSError pointer. If something does indeed go wrong in that method, I can populate the NSError reference with error data and return nil from the method. Example: - (id)

HTTP status code 0 - Error Domain=NSURLErrorDomain?

。_饼干妹妹 提交于 2019-11-26 22:05:24
I am working on an iOS project. In this application, I am downloading images from the server. Problem: While downloading images I am getting Request Timeout . According to documentation HTTP status code of request timeout is 408 . But in my application, I am getting HTTP status code 0 with the following error Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo=0xb9af710 {NSErrorFailingURLStringKey= http://xxxx.com/resources/p/PNG/1383906967_5621_63.jpg , NSErrorFailingURLKey= http://xxxx.com/resources/p/PNG/1383906967_5621_63.jpg , NSLocalizedDescription=The request

Objective-C Exceptions

£可爱£侵袭症+ 提交于 2019-11-26 18:27:48
I have just completed an iPhone app programming course. As part of the course, I saw Objective-C provides exception handling using the @try directive The system library does not use exception handling, preferring to return nil I asked if I should use exception handling for new code I wrote (e.g. if I write both the front-end and logic code, so the communication between them is in my hands) but I was told no, one should not use exceptions for new code. (But he failed to elaborate, then the class moved on, I thought perhaps the reason would become clear later..) Surely exceptions are superior to