2

What is the difference between strong vs copy in objective-c? Which one should i be using?

I know copy prevents the value of the instance variable from changing if set with a mutable string that is later changed itself. Anything else?

Kermit the Frog
  • 3,789
  • 6
  • 30
  • 39
  • 1
    "Which one should I be using?" It depends upon your needs. Sometimes you need to make sure that your class has its own copy or that it cannot be mutated, in which `copy` is correct. Sometimes you don't care and really want a `strong` reference to some other object. Both `strong` and `copy` (as well as `weak`) have situations where they are, respectively, appropriate. Ask a question about a particular scenario, and we can help you (if it's not already obvious after reading the post to which Josh referred you). – Rob Nov 11 '13 at 21:34

1 Answers1

1

strong increases retain counter of an object by 1.

copy creates an object's copy with retain counter 1.

If you use ARC you can't access to retain counter, but the approach is the same as for MRC.

Sviatoslav Yakymiv
  • 7,787
  • 2
  • 20
  • 43