Home > DeveloperSection > Interviews > What is the difference between retain & assign?

Posted on    August-02-2015 11:44 PM

 iPhone iPhone  Ios  Objective C 
Ratings:
 1 Answer(s)
  263  View(s)
Rate this:

Tarun Kumar

Total Post:107

Points:535
Posted on    August-02-2015 11:44 PM

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

if (obj1 != ob2)

{

   [obj1 release];

   obj1 = nil;

   obj1 = obj2;

}

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

if (obj1 != obj2)

{

   [obj1 release];

   obj1 = nil;

   obj1 = [obj2 retain];

}


Don't want to miss updates? Please click the below button!

Follow MindStick