Reputation: 786
Assuming that I wrote the code below in a class A:
-(NSArray *) returnListNames {
NSArray *returnList = [NSArray arrayWithArray:myListNames];
return (returnList);
}
And in a class B I get that list in some scope in this way:
{
/* Without ARC I would retain the array returned from ClassA
to guarantee its reference like this:
[[myClassA returnListNames] retain]; */
NSArray *myNames = [myClassA returnListNames];
}
Considering that the returnList
was allocated using an autorelease method, how can I guarantee that I won't lose the reference to it using ARC (under which I can't use retain
)?
Will I have to use [[NSArray alloc] init]
on the myNames
array? Or I must use alloc
on returnList
instead of an autorelease method? Or can I just rely on ARC? Or is there another solution?
Upvotes: 7
Views: 2153
Reputation: 723438
ARC will handle this for you, so you can just rely on it and go about your business with that array. If it sees that you need to retain myNames
, it will add a retain call for you for example, or do whatever else it actually does when you compile the code that uses it.
Upvotes: 11