LoginSignup
0
0

More than 5 years have passed since last update.

[iOS] Custom NSError

Last updated at Posted at 2015-04-23

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;
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0