Should one use
@property (nonatomic, weak, readonly)
or
@property (nonatomic, readonly)
?
Weak has the advantage of nil-ing out the instance if it gets deallocated, but is readonly implying weak? Should one explicit declare a property as weak if it want the weak behaviour?
If you want to keep a pointer to an object that you don't own but want it to be valid only as long as it exists, then you want to use a weak pointer because when it gets deallocated by the owner, your pointer will automatically get set to nil and won't be pointing to memory that it shouldn't be.
These both have differnect meaning, readonly doesn't make any differnce if it is weak or strong.
@property (nonatomic, weak, readonly)
@property (nonatomic, readonly)
You can also find some reference here.
Weak or strong is by no means related to readonly or readwrite. None implies the other.
A strong relation takes ownership. A weak does not but it receives the service of being nullified upon deletion of the related object.
Readonly suppresses a setter (afaik). The property cannot be changed from outside its class. Readwrite (wich is the default if none is stated) allows changes to the property.
That's basically it. That are two settings which are not related to each other. They work in all thinkable comibnations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With