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? :)
If you create an object using a method that begins with init, new, copy, or mutableCopy, then you own that object and are responsible for releasing it (or autoreleasing it) when you're done with it. If you create an object using any other method, that object is autoreleased, and you don't need to release it.
A static, plain-text Unicode string object that bridges to String ; use NSString when you need reference semantics or other Foundation-specific behavior.
The core attributes of an NSError object are an error domain (represented by a string), a domain-specific error code and a user info dictionary containing application specific information.
-[NSError localizedDescription]
.
(Also, every ObjC object inherited from NSObject implements -description
which returns an NSString.)
for folks new to objective c (me), following is example code that makes accepted answer from 'KennyTM' work ->
[self showAlertWithTitle:@"Error:" withMessage:error.localizedDescription];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With