0

I have used ARC and built apps before that supported iOS 4.3, but as soon as I started using weak, because a Tree has a strong reference to node, and node has a reference back to the tree, which should be a weak reference:

@property (weak, nonatomic) NSTree *treeThatIBelong;

(NSTree is a class that I created in my own code).

In this case, the target of iOS 4.3 cannot be used, as the compiler error is "weak... is not supported in the deployment target", and the error will only go away if it is iOS 5.0 or higher. So if we have a weak, we can't deploy to iOS 4.3? Is there a workaround if we want to support iOS 4.3 and still use ARC?

Jeremy L
  • 3,770
  • 6
  • 41
  • 62

1 Answers1

1

The workaround is to not use weak if you need to deploy to iOS 4.3 or earlier. weak requires runtime support that's not present until iOS 5.0.

For iOS 4.3 and earlier you can use assign, which of course is not a zeroing weak reference and therefore just turns into garbage when the referenced object is deallocated. Which is exactly what you have to deal with already when using MRR instead of ARC.

Lily Ballard
  • 182,031
  • 33
  • 381
  • 347
  • so in order to deploy to iOS 4.3 and up, use `assign` instead of `weak`... and is there anything that needs to be done besides this? – Jeremy L Sep 06 '12 at 07:50
  • @JeremyL: Just be aware of the pitfalls of `assign`, which treats the value as `__unsafe_unretained`. – Lily Ballard Sep 06 '12 at 17:39
  • actually, if I drag a UIButton into the `.h` file as an IBOutlet, then if the deploy target is iOS 5, it will be `weak`, and if I change the deploy target to `iOS 4.3`, then drag another button to the `.h` file, then it won't use `weak`, but will use `unsafe_unretained` instead. So should `assign` be used or `unsafe_unretained` be used? – Jeremy L Sep 08 '12 at 07:56
  • 2
    assign and unsafe_unretained are the same – Catfish_Man Sep 08 '12 at 20:16