What is the difference between weak and strong property setter attributes in Objective-C?
@property(retain, [weak/strong]) __attribute__((NSObject)) CFDictionaryRef myDictionary;
What is the impact and benefit?
I heard that weak is not available on iOS 4 and we need to use assign.
Is weak similar to assign?
You either have ARC on or off for a particular file. If its on you cannot use
retainreleaseautoreleaseetc… Instead you usestrongweakfor properties or__strong
__weak
for variables (defaults to__strong). Strong is the equivalent to retain, however ARC will manage the release for you.The only time you would want to use weak, is if you wanted to avoid retain cycles (e.g. the parent retains the child and the child retains the parent so neither is ever released).
The ‘toll free bridging’ part (casting from
NStoCF) is a little tricky. You still have to manually manageCFRelease()andCFRetain()for CF objects. When you convert them back to NS objects you have to tell the compiler about the retain count so it knows what you have done.Its all here.