I've seen code examples (from the book Beginning iPhone 4 Development) where they both declare ivars inside the interface block and then declare properties for the same. Like this:
@interface ViewController : UIViewController {
UITableView *table;
}
@property (nonatomic, retain) IBOutlet UITableView *table;
What would be the purpose/benefit of this? As I understand that with the modern runtime version (iPhone and 64-bit OS X applications) you only need to declare properties and can leave out declaring the ivars inside the interface block. According to this answer in a similair thread it would be for debugging purposes. But are there any other benefits except for debugging that you would use this approach?
Cheers,
Peter
Explicitly declaring ivars gives you the possibility to internally use a specialized type for the ivar.
A typical example is an internally mutable object that can be accessed from outside in a readonly, immutable way.
Example:
Of course the object returned from the
bars
property is not really immutable. But the point is that the API does not reveal its mutability.Note that I used the fancy new private-ivars-in-implementation style. It's depending on the modern runtime as well as the clang compiler.