Playing with NSError
I was playing with NSError recently, and here you can find how to deal with it.
1. How to “create” error
// if your method returns BOOL // true - OK // false/NO - indicates error // if your method returns int // return == 0 - OK // return != 0 - error // if your method returns pointer // return != nil - OK // return == nil - error -(BOOL) generateError: (NSError **) error { if(error != nil) { NSMutableDictionary *errorDetail = [NSMutableDictionary dictionary]; [errorDetail setValue:@"Description of the error" forKey:NSLocalizedDescriptionKey]; *error = [NSError errorWithDomain:@"domainName" code: 1 userInfo:errorDetail]; return false; } }
In the code you can do as follows:
NSError *error = nil; BOOL result = [id generateError: &error]; if(result == NO) { // you can deal with error object here }
September 28th, 2011 in
main entries