tags:

views:

34

answers:

1

I want to achieve something similar to what these guys do here:

- (NSUInteger)countForFetchRequest:(NSFetchRequest *)request error:(NSError **)error

like you can see, you pass an NSError pointer and that nice method will assign a real NSError object to your pointer in case there is an error. So the cool thing about this is, that the method returns an NSUInteger but can ALSO return an NSError, without having to mess around with ugly and fat arrays or dictionaries.

So how could I assign an object to the passed-in error pointer?

+2  A: 

It's easy. This Apple guide shows how you might implement a method that returns an NSError object. But to make a long story very, very short:

- (NSUInteger)countForFetchRequest:(NSFetchRequest *)request error:(NSError **)error
{
    //Do stuff, including make MyCustomErrorDomain and errCode and eDict.
    *anError = [[[NSError alloc] initWithDomain:MyCustomErrorDomain code:errCode userInfo:eDict] autorelease];
    //Do some more stuff.
}

Note the asterisk. :)

andyvn22
This is just a normal, everyday pointer dereference, by the way. Any book on C should cover it.
Chuck