6
votes

I know there have been numerous write ups on 'strong' vs. 'weak'. But all docs says that both are 100% synonyms for each other and you can use 'strong' in replace of 'retain', and vice versa.

My question is: if they are same, why did Apple introduce the new 'strong' keyword? I have tested both in a sample project, and both the 'strong' and 'retain' property attributes appear to do the same thing. Don't you think that if Apple introduced the 'strong' attribute, it should disallow the use of 'retain' attribute? Or am I missing something?

1
the strong and retain are pretty much the same, but because in ARC you don't need to worry about retaining-releasing objects, the strong is logically much more proper for a property in ARC... like in MRR the retain has the opposite equivalent as release or autorelease, in ARC environment the strong has no such opposite equivalent, this is why logically more correct to use the strong instead of the retain in ARC; if that makes sense to you.holex
@Katoch I have read that its pointing to the same thing strong = retain that I understand. But question is why to create a doubt in mind of developer (although i always use strong) as retain was something related to manual memory management, they should have completely stopped the use of retain in ARC projects , why it still has its place in ARC?Anshul
one line answer. retain is in non-arc and strong is in arc..Deepak Thakur

1 Answers

11
votes

retain is a leftover from the pre-ARC days where you would increase/decrease an objects retain count depending on whether you wanted it to hang around in memory.

Obviously with ARC you no longer have to worry about this and I suspect that retain may simply have been left in for ease of use for the more veteran objective-c programmers out there.

The keywords that are most prevalent with arc are: (strong, weak, nonatomic, readonly, copy).