开发者

How are these ObjC declarations different: ie what is this really doing?

开发者 https://www.devze.com 2023-01-05 07:51 出处:网络
I\'m trying to understand what this is doing in each case. Can someone explain what the开发者_C百科 first case is doing in detail and how it differs from the second? Thanks // :)

I'm trying to understand what this is doing in each case. Can someone explain what the开发者_C百科 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;
}


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];
0

精彩评论

暂无评论...
验证码 换一张
取 消