Re: NSMutableArray contract
Re: NSMutableArray contract
- Subject: Re: NSMutableArray contract
- From: "Hank Heijink (Mailinglists)" <email@hidden>
- Date: Fri, 01 Apr 2011 09:37:02 -0400
On Apr 1, 2011, at 9:29 AM, Carlos Eduardo Mello wrote:
> Hi people,
>
> I just realized I may be doing something dangerous with an NSMutableArray. I searched Guides and References on this but couldn't find an explicit answer:
>
> - Does an NSMutableArray guarantee to retain an object on addObject:?
Yes.
> - Does it ever make a copy of the original instead of retaining it?
No, unless you initialize the array with [[NSMutableArray alloc] initWithArray:otherArray copyItems:YES].
> - As long as I am sure the object will not be removed (or replaced) from the array, is it safe to assume that the object I passed to addObject: is the exact same object inside the array?
Yes. Of course, you can modify the object but the pointer should stay the same.
> The reason I am asking this is because in a couple of hard-to-debug places in my code I use an object I just added to a mutable array counting on it being the same pointer as inside the array (because other parts of the code will need it there later).
You can of course check that by logging the address of the object. I wonder what you're observing that makes you think this is the problem?
Good luck,
Hank
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden