Personal Project

Sunday, October 13, 2013

Why do you write "assign" in a property declaration on an Objective-C class ?


1. assign / unsafe_unretained (no memory management shall be done with this property, it is handled manually by the person assigning the value) (default if not ARC or object type).

2. Assign is used for C primitive property to replace a variable with new values.




Property :
  • nonatomic (does not enforce thread safety on the property, mainly for use when only one thread shall be used throughout a program)
  • atomic (enforces thread safety on the property, mainly for use when multiple threads shall be used throughout a program) (default)
  • retain / strong (automatically retains / releases values on set, makes sure values do not deallocate unexpectedly) (default if ARC and object type)
  • readonly (cannot set property)
  • readwrite (can both set and get property) (default)
  • assign / unsafe_unretained (no memory management shall be done with this property, it is handled manually by the person assigning the value) (default if not ARC or object type)
  • copy (copies the object before setting it, in cases where the value set must not change due to external factors (strings, arrays, etc).
  • weak (automatically zeroes the reference should the object be deallocated, and does not retain the value passed in)


Good ref: 
http://rdcworld-iphone.blogspot.in/2012/12/variable-property-attributes-or.html


No comments:

Post a Comment