Properties in Detail

When getting into Objective-C programming, the declaration of properties is sometimes confusing. In Java, you declare some private variables in the class, and then create getters and setters as needed. Things seem much more involved in Objective-C, so a more detailed look at the properties is warranted. The properties in Objective-C are very similar to the automatic properties available in C#.

When you declare a property like this in Objective-C:

@property (nonatomic, strong) NSString *title;

you actually tell the compiler to do several things in a single line:

Image Declare a class variable called ...

Get Learning Mobile App Development: A Hands-on Guide to Building Apps with iOS and Android now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.