I’m not sure if this is correct or not:
- (void)parseSomething:(id)targetObject error:(NSError **)error {
NSError *parserError = nil;
[myParser parse:targetObject error:&parserError];
if (parserError != nil) {
*error = parserError;
}
}
the line:
*error = parserError;
I set error in parameter to be a local error, is it done correctly?
or should I do:
error = &parserError;
instead?
You need to make sure
errorisn’t nil before you try to dereference it. Also, there is no need for the local NSError. It’d write that code this way:But if you really wanted the locale variable (or for demonstration purposes). then this:
Also, most methods that have an
NSErrorout parameter like this usually have a BOOL return value or some other return value to indicate success or not. You shouldn’t rely in the error parameter to indicate whether there was an error or not.