开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜