Re: NSError question
Re: NSError question
- Subject: Re: NSError question
- From: Conor <email@hidden>
- Date: Mon, 26 Feb 2007 20:07:05 +0100
> 1) Why are "double pointer" NSError** used instead of a single
> pointer ?
Because NSError is not mutable. If you create an error and pass it to
the method, the method can't change it to add the error description. Having
a mutable error object is inefficient, as most of the time it's not used but
you are spending the time to create it every single time.
> 2) When debugging, how should I read the NSError objects ? With
> "po theError" or "po *theError" ?
Create a pointer for an error object and then pass that address to the
method. If an error occurs the method will create the error an place a
pointer to it at your address, you will then be referencing an error at that
address after the method returns. In the following code an error occurs and
it prints the localized description to the log. Memorize this format and you
can use it on all functions that take an error.
NSString *someString = @"Hello";
NSString *pathToSave = [@"~/Desktop/NON_EXISTING_FOLDER/sample.txt"
stringByExpandingTildeInPath];
NSError *anError = nil; //It's important to initialize the address
[someString pathToSaveatomically:YES encoding:NSUTF8StringEncoding
error:&anError];
if (anError) {
NSLog(@"There was an error: %@", [anError localizedDescription]);
}
Usual disclaimer about writing code in mail applies.
Regards,
Conor
http://www.bruji.com/
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden