Darren Findlay
Darren Findlay

Reputation: 2563

Synthesised properties for primitive data types using ARC -- weak or assign?

I was wondering what is the correct way to write synthesised properties for primitive data types (like bool) when ARC is enabled.

I used to use this before ARC:

@property(assign) bool isOn;

But it is my understanding (maybe wrong) that you shouldn't use assign when ARC is enabled. I tried replacing this with weak but I get the error -

Property of "weak" attribute must be of type object.

Should I continue to use assign?

Upvotes: 19

Views: 6671

Answers (3)

Ambadas
Ambadas

Reputation: 1

When ARC Enabled you can write synthesised properties for primitive data like(ex:BOOL).. @property(unsafe_unretained) bool isOn;

Upvotes: 0

Totumus Maximus
Totumus Maximus

Reputation: 7583

Seems you need to read up on a certain subject here. Check: http://clang.llvm.org/docs/AutomaticReferenceCounting.html

Check chapter 4 ;) Here you will read that assign is fine with ARC.

Upvotes: 4

Rob Bajorek
Rob Bajorek

Reputation: 6570

Assign is fine. ARC stands for "Automatic Reference Counting", and primitive data types do not have reference counts.

Weak failed because there is no object, nor any references for ARC to manage.

Upvotes: 29

Related Questions