Using weak with readonly property?

cocoa, ios, objective-c, properties

Solution

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.

Problem

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?

Original source

Related problems