Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between parentheses and square bracket in objective-c

Tags:

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 World!"];?

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

like image 575
Leon Avatar asked Feb 02 '23 15:02

Leon


1 Answers

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];
like image 116
dtuckernet Avatar answered Feb 05 '23 06:02

dtuckernet