What's the Point of (NSError**)error?

iphone, objective-c, pointers

Solution

If you just passed in a pointer, all the method could do would alter the already existing NSError object that you are pointing to.

By passing in a pointer to a pointer, it can create new NSError objects and leave you with a pointer that points to them.

Problem

Example: The `-save:` method of `NSManagedObjectContext` is declared like this: ``` - (BOOL)save:(NSError **)error ``` Since NSError is already a class, and passing a pointer would actually have the effect of modifying this object inside the implementation of `-save:`, what's the point of passing a pointer to a pointer here? What's the advantage/sense? Usage example: ``` NSError *error; if (![managedObjectContext save:&error]) { // Handle the error. } ```

Original source

Related problems