开发者

How to explain this Objective C method declaration "- method:parameter;"

Declaring, implementing and using method like this:

Test.h:

- method:parameter;

Test.m:

- method:parameter{
    return nil;
}

Using:

[test method:anObject];

There is no return-type and parameter-type, but it works without an开发者_StackOverflow社区y warning or error. Can somebody explain it?


As the Objective-C Programming Language document states:

If a return or parameter type isn’t explicitly declared, it’s assumed to be the default type for methods and messages — an id.

So:

- method:parameter;

effectively means:

- (id)method:(id)parameter;

and, correspondingly:

- method:parameter{
    return nil;
}

effectively means:

- (id)method:(id)parameter{
    return nil;
}


From The Objective-C Programming Language:

If a return or parameter type isn’t explicitly declared, it’s assumed to be the default type for methods and messages—an id.


Default type in Obj-C is id. So here the both the return and parameter is id.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜