NSArray *A = [NSArray arrayWithObject:@"x"];
NSError is a little different. For example here we did this:
In the NSString Class Reference it looks like this:
So, what's with NSError **, and what's with &e ? And what does the NSError object actually contain when an error occurs?
NSError inherits from NSObject so it can't be that complicated. Almost invariably you do not actually create an NSError object. Instead, you declare the variable, and then pass it into a method which fills it out for you if an error occurs. The NSError object is a member of a real Cocoa class, with methods and everything.
In the first function above:
NSError *e;
looks normal.In
error:&e
the "address-of operator" &
means that we are passing in the address of our pointer to the NSError object, rather than the pointer itself So, this is a pointer-to-a-pointer kind of thing, but constructed using "&". I learned about this in C++, but it does actually exist in C.
In the class reference code, the variable is an NSError **, that is, a pointer-to-a-pointer.
I'm not sure why this it's done this way. It kind of reminds me of "Handles"---old time Apple stuff that I remember from the book "Inside Macintosh."
As for what messages NSError object responds to, it may respond to:
• domain (returns a string)
• code (returns an integer that may be used as an enumerated type)
• userInfo (returns a dictionary that is often empty)
So, the sky's the limit for what can be there.