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];
精彩评论