2

From reading Property vs. ivar in times of ARC, I understand that ARC will use the __strong ownership qualifier when I directly get or set a strong property's autosynthesized associated instance variable but will neither call custom getters or setters nor trigger KVO.

But, if I declare a property as weak like so:

@property (weak, nonatomic) id <XYZExampleViewDelegate> delegate;
  1. Will the autosynthesized associated instance variable take on the __weak ownership qualifier?

    For example, will _delegate = delegate (vs self.delegate = delegate) in my implementation of

    - (id)initWithDelegate:(id <XYZExampleViewDelegate>)delegate
    

    perform assignment according to the __weak qualification?

  2. What about for a property declared with copy?

Community
  • 1
  • 1
ma11hew28
  • 121,420
  • 116
  • 450
  • 651

1 Answers1

4
  1. Yes, the property modifier weak implies __weak ownership. A property's associated instance variable (or backing ivar) is created with the ownership qualifier implied by the property's modifier. See Clang documentation on ARC property declarations for a list of property modifiers and which ownership qualifiers they imply.

  2. The property modifier copy implies __strong ownership. So, when setting the backing ivar directly, the new pointee is retained but not copied. To copy it, use the setter.

ma11hew28
  • 121,420
  • 116
  • 450
  • 651
  • 3
    For (2), think of it this way: *copy + weak makes no sense*. The runtime would create a copy of the object, assign it to the `weak` instance variable, then immediately release it because there are no strong references to the copied object... – bbum Oct 26 '13 at 23:45