开发者

Difference between parentheses and square bracket in objective-c

This might sound dumb but why some functions/methods in Objective-C use parentheses rather than square brackets?

E.g. why it's not [someObject NSLog: @"Hello Wo开发者_开发百科rld!"];?

And when should I use parentheses but not square brackets? Thanks.


Parentheses are used for C functions (like CGRectMake) while brackets are used for objective-c methods.

See example:

// Method to create C Structure
CGRect frame = CGRectMake( 0, 0, 100, 100 );

// Objective-C method call (sending message)
UIButton *button = [[UIButton alloc] initWithFrame:frame];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜