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: Quincey Morris <email@hidden>
- Date: Thu, 11 Aug 2016 17:47:15 -0700
- Feedback-id: 167118m:167118agrif8a:167118szerIvDxml:SMTPCORP
On Aug 11, 2016, at 17:16 , Steve Sisak <email@hidden> wrote:
>
> This thread seems to have gone off into the weeds by way of tortured analogy. ;-)
OK, spoil the fun!
But …
> This way if you want to add an object to a collection, calling -copy has the effect of freezing the current value — the immutable class can optimize this by just returning a new reference to the same object, but the caller doesn’t have to know whether the object was immutable or a mutable subclass.
I think the important point (which may be OT, but is still worth making) is there’s no formal definition of immutability in Obj-C. (There is in Swift.) There’s no clarification of what “values” means in the official NSCopying protocol description, so who knows which “values” have to be “identical” in the copy. If the object’s “values” are themselves class instances, there’s no clarification of what “identical” means, either.
At risk of starting a different fire, or dying in different weeds, I’ll point out that *all* Obj-C objects (except for tagged pointers and compile time NSString literals) are strictly-speaking mutable, because they all have a public “retainCount” property that changes over time.
By common consent, we agree to exempt certain things from disqualifying an object from immutability. The mutable retain count is one such thing. It is up to each class to decide what other things might also be exempt.
_______________________________________________
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