Blog

Difference between retain & assign

Feb 15, 2013 Blogs | iOS
In this blog I will explain basic difference between retain & assign.

Assign creates a reference from one object to another without increasing the source's retain count.

if (_variable != object)

{    

 [_variable release];   

  _variable = nil;  

  _variable = object; 

 }

Retain creates a reference from one object to another and increases the retain count of the source object.

if (_variable != object)

{     [_variable release]; 

    _variable = nil;   

  _variable = [object retain];  

}

Sachin Bhardwaj

Sachin Bhardwaj is a software developer working with Apple technologies including Xcode, iOS, iPhone, iPad, iPod and Mobile app store. 

  • 53rank
  • 552K readers
COMMENT USING

PREMIUM SPONSORS

Hire Mobile & Web Developer on demand. 100% satisfaction. Try for 1 week or Money Back. Local and remote developers available all over USA.

Latest Blogs