Does NSArray:lastObject return an autoreleased object?

Posted by Kyle on Stack Overflow See other posts from Stack Overflow or by Kyle
Published on 2010-05-23T23:12:51Z Indexed on 2010/05/23 23:21 UTC
Read the original article Hit count: 437

Filed under:
|
|

I'm working on an iPhone project where I would like to retrieve an object from an NSMutableArray, remove the object from the array and then use it later. The code looks something like this:

NSMutableArray * array;
// fill the array
NSObject * obj = [array lastObject];
[array removeLastObject];
// do something with obj (in the same function)

array is the only entity with a retain on the object that is being accessed. Is this safe to do? I would assume that this would only work if lastObject autoreleased the object which is something that I can't figure out if it does.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c