Search code examples
objective-cios7automatic-ref-countingweak-referencesstrong-parameters

iOS7 is there a reason to use assign instead of weak for properties?


I've encountered several "message sent to deallocated instance" bugs within my app and traced them to the use of

@property(nonatomic,assign)NSObject* object;

Replacing them with

@property(nonatomic,weak)BuffCollection* buffCollection;

solves the problem. Should I define all of my properties where I don't want to use strong to be using weak instead of assign?


Solution

  • Theres a great explanation of all the different property attributes here.

    If you are using ARC, the basics are to use strong for obj-c objects you want to retain, weak for obj-c objects you don't want to retain and assign for non-objective-c (so C) primatives. Strong is default.