With the objective-c, some functions may have some errors, for example connection errors.
In this situation, we can pass a NSError*
pointer to the function and check the error after calling the function.
Code example:
- (void)getDataWithError:(NSError **)error {
if(error) { //Check if the parameter is nil
*error = [[NSError alloc] initWithDomain:@"ConnectionError"
code:1001
userInfo:nil];
}
}
Also can do something like this:
NSError *urlConnectionError = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:request
returningResponse:&response
error:&urlConnectionError];
*error = urlConnectionError;