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.
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];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With