Question

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 through ok, but the issue is I need to convert the NSError into an NSString so I can either return it back or run some if() statements on it.

Any ideas? :)

Was it helpful?

Solution

-[NSError localizedDescription].

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

OTHER TIPS

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

[self showAlertWithTitle:@"Error:" withMessage:error.localizedDescription];

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

More in the docs.

I found that there are three main methods to NSError:

  • error (NSInteger)
  • domain (NSString)
  • userInfo (NSDictionary)

To get all the error details:

NSError * err;
...
[NSString stringWithFormat:@"%@", err];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top