8
I was creating a sample project in xcode 4.2 and noticed that the new project was setup with ARC.
I have a method shown below. Previously, I would have autoreleased the cell in the method and let the caller's table view retain the cell. With ARC, autoreleasing would not be possible,
- (UITableViewCell*) getCellForIndex:(int)index {
UITableViewCell *cell =
[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
if (index == 0)
cell.textLabel.text = profileToUse.name;
if (index == 1)
cell.textLabel.text = profileToUse.sex;
if (index == 2)
cell.textLabel.text = profileToUse.city;
return cell;
}
When I running the analyze tool on the code above, it says that there is a potential memory leak of the object 'cell'.
How should the above be written using ARC so that the analyze warning will go away? What am I doing wrong?
Thanks.