Returning an NSString from an NSError

前端 未结 5 1803
暗喜
暗喜 2021-02-06 21:12

I am using the NSURLRequest class in my iPhone app, and the method that calls it returns an NSString which is great for when the connection goes throug

相关标签:
5条回答
  • 2021-02-06 21:53

    To get all the error details:

    NSError * err;
    ...
    [NSString stringWithFormat:@"%@", err];
    
    0 讨论(0)
  • 2021-02-06 21:56

    You could try the localizedDescription method, which returns a string.

    More in the docs.

    0 讨论(0)
  • 2021-02-06 21:56

    I found that there are three main methods to NSError:

    • error (NSInteger)
    • domain (NSString)
    • userInfo (NSDictionary)
    0 讨论(0)
  • 2021-02-06 22:05

    for folks new to objective c (me), following is example code that makes accepted answer from 'KennyTM' work ->

    [self showAlertWithTitle:@"Error:" withMessage:error.localizedDescription];
    
    0 讨论(0)
  • 2021-02-06 22:10

    -[NSError localizedDescription].

    (Also, every ObjC object inherited from NSObject implements -description which returns an NSString.)

    0 讨论(0)
提交回复
热议问题