A little macro magic for handling NSError** within a method

I don’t like checking if the caller passed me a nil NSError** in my own methods, especially if the implementation is somewhat lengthy, so I’ve put together a very basic C macro that declares an autoreleasing NSError* to use as temporary storage in case of a null NSError** parameter from the caller:

Imagine that I have a method named foo that takes a single NSString* and an optional NSError**:

Now I don’t need to check if I’ve been passed a valid NSError** pointer, because it will be assigned to the local tempError variable if it was nil.

Leave a Reply

Your email address will not be published. Required fields are marked *