Rick
Rick

Reputation: 197

Objective-C Property Access

What is the difference in accessing an objects properties or methods via foo.property to [foo property]?

Upvotes: 5

Views: 2176

Answers (2)

Vadoff
Vadoff

Reputation: 9419

At compile time they're treated the same, but one benefit of using dot notation to handle properties is that while coding, after placing the "." code completion/code window will only show valid properties as suggestions whereas using brackets will show all methods.

Upvotes: 0

iKenndac
iKenndac

Reputation: 18776

Nothing! Dot-notation is "syntactic sugar" introduced in Objective-C 2.0. In fact, the compiler converts foo.property to [foo property] during compile-time, so they compile to exactly the same thing.

It's simply a matter of which you prefer.

Upvotes: 10

Related Questions