Skip to content

Instantly share code, notes, and snippets.

@hlung
Last active January 3, 2016 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hlung/8534467 to your computer and use it in GitHub Desktop.
Save hlung/8534467 to your computer and use it in GitHub Desktop.
This is how to check if an `NSError**` or the data it points to is empty. Very straight forward, we check if pointer is nil before checking if the data it points to is nil.Doing `*error` on a nil pointer will raise an exception.
+ (void)errTest2:(NSError**)error {
// Use error object ONLY IF it is provided, otherwise it will CRASH!!!
if (error != NULL) {
NSLog(@"Creating error object...");
*error = [NSError errorWithDomain:...];
}
else {
NSLog(@"No error object provided, skip error object creation.");
}
}
@clementprem
Copy link

*error will initially point to a nil pointer so the if block will always fail & move to else.

@hlung
Copy link
Author

hlung commented Nov 12, 2015

Sorry, fixed. Now checking against NULL instead :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment