Re: Objective-C basics - (Why NSNumber conforms to NSCopying protocol)
Re: Objective-C basics - (Why NSNumber conforms to NSCopying protocol)
- Subject: Re: Objective-C basics - (Why NSNumber conforms to NSCopying protocol)
- From: David Duncan <email@hidden>
- Date: Wed, 10 Aug 2016 23:40:00 -0700
> On Aug 10, 2016, at 11:32 PM, Sasikumar JP <email@hidden> wrote:
>
> Hi,
>
> This may be very basic question. I am curious to know the details.
>
> what was the reason NSNumber conforms to NSCopying protocol.
>
> NSNumber is immutable class, Making a copy of NSNumber object returns the
> same reference.
>
> Is there any case where NSNumber returns the new object? if not, then what
> is the purpose of conformance to NSCopying protocol.
There is nothing stopping a developer from subclassing NSNumber, and if that developer decided to create MyMutableNumber that otherwise conformed to the NSNumber interface, the developer would need to implement -copyWithZone: to do the right thing. If NSNumber doesn’t implement NSCopying, then the subclasser can’t hope to get the correct behavior in this case.
--
David Duncan
_______________________________________________
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