inessential by Brent Simmons

Property Declarations

I’ve had a few different conventions for how I declare properties.

Here’s how I do it these days:

If it’s strong, I omit the strong keyword, since properties are strong by default.

@property (nonatomic) NSDate \*dateCreated;

I always put nonatomic first (and almost every single property is nonatomic), so things line up a little better:

@property (nonatomic) NSDate \*dateCreated;
@property (nonatomic, weak) NSArray \*notes;
@property (nonatomic, assign) NSUInteger numberOfCats

readonly and readwrite come last:

@property (nonatomic, assign, readwrite) CGFloat heightInCubits;

I find that this helps me understand quickest. My brain filters out the nonatomic part. Strong is the most common thing and thus omitted, which makes it easier to pick out weak, assign, readwrite, and readonly.

I never use the getter= thing, because I find it easier when the getter and setter have the same name. It’s too much to remember when there’s a custom getter name.

PS I don’t mean that I order the properties in any particular order, though. It could look like this:

@property (nonatomic, assign, readwrite) CGFloat heightInCubits;
@property (nonatomic, weak) NSArray \*notes;
@property (nonatomic, assign) NSUInteger numberOfCats
@property (nonatomic) NSDate \*dateCreated;