Re: copy and mutableCopy
Re: copy and mutableCopy
- Subject: Re: copy and mutableCopy
- From: Roland King <email@hidden>
- Date: Sun, 27 Apr 2014 18:07:14 +0800
On 27 Apr, 2014, at 5:06 pm, John McCall <email@hidden> wrote:
> On Apr 27, 2014, at 2:00 AM, Dave <email@hidden> wrote:
>> A long time back, I remember reading something about the way in which copy and mutableCopy are implemented. I think basically it said that:
>>
>> someObject = [someOtherObject copy];
>>
>> or
>>
>> someObject = [someOtherObject mutableCopy];
>>
>> Wouldn’t necessarily allocate any extra data storage. I’ve been searching for it to refresh my memory, but I can’t see to find it anywhere. Does anyone know if this document or something like it exists somewhere?
>
> I don’t know if there’s a document, and like a lot of things with ObjC the actual guarantees are pretty weak, but implementations of these methods on immutable types have been turning into essentially “return [self retain];" for quite some time. But that’s when the actual dynamic type is guaranteed-immutable, e.g. something constructed as an NSArray, not just something that’s immutable by convention, e.g. an NSMutableArray that you’re passing around as an NSArray.
>
There are indeed no guarantees. It is often the case that an immutable object 'copies' itself by just returning itself but it doesn't have to, it can make a new object if it wants. I can't think of a case where a mutable object could copy itself without allocating extra storage so in the mutableCopy case, this almost definitely isn't correct.
_______________________________________________
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