I would like to know what is the difference between dot notation and using square bracket.

Recommended Answers

Nothing really it is just a matter of personal taste, you can use either as you wish.

Jump to Post

All 3 Replies

Nothing really it is just a matter of personal taste, you can use either as you wish.

There are certain situiations where message call are perferred over dot notation.

When using custom getters (same for setters) [obj getPropertyA] is more usefull than obj.propertyA because the formor is searchable. While you can search for "propertyA", you would find both getters and setters.

Convention for getters and setters in ObjC encourages getter method be called the variable name and the setter be called the variable name preceeded by set.

getter: [obj myVar] or obj.myVar
setter: [obj setMyVar:value] or obj.myVar = value

This kind of negates the example given above. Dot notation and bracket notation are interchangeable and are largely left to the developers style and personal preference.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.