views:

54

answers:

1

I'm trying to understand what this is doing in each case. Can someone explain what the first case is doing in detail and how it differs from the second? Thanks // :)

//declare in first case
NSManagedObjectModel *mom();

NSManagedObjectModel *mom() {
 static NSManagedObjectModel *mom = nil;
//implementation goes here...
 return mom;
}

vs.

//no declaration in second case
- (NSManagedObjectModel *) mom {
 static NSManagedObjectModel *mom = nil;
//implementation goes here...
 return mom;
}
+3  A: 

The first is a standalone function; it's not tied to a class. You'd call it like:

NSManagedObjectModel *retVal = mom();

The second is an instance method definition, and thus is defined in the context of a class. You'd call it like:

NSManagedObjectModel *retVal = [someObject mom];
mipadi