Earl Grey
Earl Grey

Reputation: 7466

Should I omit the "assign" qualifier when declaring primitive properties?

My colleague objected in code review that declaring a CGFloat obj-c property with assign qualifier is superfluous as it is assign implicitly. He says this is all I need.

@property (nonatomic) CGFloat cornerRadius;

However two other colleagues say that it helps to explicitly say assign to improve readability and ensure that in case a fundamental changes happening in clang when the default becomes something else, my explicit assign will be still there and I can sleep better knowing that.

Is this qualifier optional and its use a matter of personal preference?

Upvotes: 0

Views: 24

Answers (1)

rmaddy
rmaddy

Reputation: 318854

They are both right. It's a style choice really. Default values are not required. But personally I put assign because it's clear and self-documenting. No need to remember what the default is.

In the end it is a personal choice or the choice of whatever coding standards you need to follow.

Update based on the updated question:

Yes, the use of assign in a property is optional and yes, it is a matter of personal preference whether you choose to use it or not.

Upvotes: 2

Related Questions