So far, the answers given so far are correct. I think the more relevant question is why you would like to do this.
It looks like you want to have a defensive programming style where the return code indicates success or failure.
Objective-C, , NSError ** ,
, :
- (NSString *)aStringWithError:(NSError **)outError {
returnString = @"OK";
if (!returnString) {
if (outError != NULL) {
NSString *myErrorDomain = @"com.company.app.errors";
NSInteger errNo = 1;
*outError = [[[NSError alloc] initWithDomain:myErrorDomain code:errNo userInfo:nil] autorelease];
}
}
return returnString;
}
:
NSError *error;
NSString *stringVariable = [self aStringWithError:&error];
if (!stringVariable) {
NSLog(@"Call failed with error: %ld", [error code]);
}
, , , , .