I've just started learning Objective-C and I'm not sure when to use dot notation vs. square brackets. I know a similar question has been asked here but I'm still not really understanding the difference. I've read that [myObject doSomething]
and myObject.doSomething
are equivalent. What I'm not sure about though is that when I use @property
to generate a method it automatically generates a setter method that I can only use with square brackets.
// MyClass.h
@interface MyClass : NSObject
@property int number;
// main.m
MyClass *object = [[MyClass alloc] init];
[object setNumber:3];
object.setNumber = 4; // Property 'setNumber' not found
Why am I getting error messages when I write object.setNumber = 4
and why can I only use square brackets for this?