[iOS] Custom NSError
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;
Author And Source
この問題について([iOS] Custom NSError), 我々は、より多くの情報をここで見つけました https://qiita.com/zhupeijun/items/11d6c7f5e30d72db331d著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .