Re: Objective-C basics - (Why NSNumber conforms to NSCopying protocol)

2016-08-11 Thread dangerwillrobinsondanger
> On Aug 12, 2016, at 11:20 AM, Steve Sisak wrote: > > Actually, to be pedantic, class cluster is an implementation detail ― was > trying to impedance match to OP’s experience level. > > Was speaking purely in terms of public interfaces (since he’s a consumer >

Re: Objective-C basics - (Why NSNumber conforms to NSCopying protocol)

2016-08-11 Thread Steve Sisak
"On Aug 11, 2016, at 9:04 PM, dangerwillrobinsondan...@gmail.com wrote: >> On Aug 12, 2016, at 9:16 AM, Steve Sisak wrote: >> >> There’s a standard idiom where immutable classes frequently have mutable >> subclasses (which expose the mutating methods). >> >> In this

Re: Objective-C basics - (Why NSNumber conforms to NSCopying protocol)

2016-08-11 Thread dangerwillrobinsondanger
> On Aug 12, 2016, at 9:16 AM, Steve Sisak wrote: > > There’s a standard idiom where immutable classes frequently have mutable > subclasses (which expose the mutating methods). > > In this case, it’s common for the immutable (super)class to adopt NSCopying > and the

Re: Objective-C basics - (Why NSNumber conforms to NSCopying protocol)

2016-08-11 Thread Quincey Morris
On Aug 11, 2016, at 17:16 , Steve Sisak 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

Re: Objective-C basics - (Why NSNumber conforms to NSCopying protocol)

2016-08-11 Thread Steve Sisak
This thread seems to have gone off into the weeds by way of tortured analogy. ;-) Going back to the OP’s question > On Aug 11, 2016, at 2:32 AM, Sasikumar JP wrote: > > what was the reason NSNumber conforms to NSCopying protocol. > > NSNumber is immutable class, Making a

Re: Objective-C basics - (Why NSNumber conforms to NSCopying protocol)

2016-08-11 Thread Britt Durbrow
> On Aug 11, 2016, at 3:32 PM, Sandor Szatmari > wrote: > > 1. If at all possible, and within reason, avoid mutable objects in > collections (your swift points address this). > It depends on the collection, and how the mutable objects are handling -hash and

Re: Objective-C basics - (Why NSNumber conforms to NSCopying protocol)

2016-08-11 Thread Britt Durbrow
> I didn’t realize that I was saying anything controversial. Oh, it’s usually the most innocuous seeming of things that ignite the biggest firestorms… :-) > On Aug 11, 2016, at 11:11 AM, Quincey Morris > wrote: > > “Stored in” is incorrect. What’s

Re: Objective-C basics - (Why NSNumber conforms to NSCopying protocol)

2016-08-11 Thread Sandor Szatmari
Quincey, > On Aug 11, 2016, at 16:26, Quincey Morris > wrote: > >> On Aug 11, 2016, at 12:50 , Sandor Szatmari >> wrote: >> >> I guess the answer is that the creation date property is not considered part >> of the 'meaning'

Re: Objective-C basics - (Why NSNumber conforms to NSCopying protocol)

2016-08-11 Thread Quincey Morris
On Aug 11, 2016, at 12:50 , Sandor Szatmari wrote: > > I guess the answer is that the creation date property is not considered part > of the 'meaning' of what the object is, and therefore would not be factored > in when writing the -hash or -isEqual: methods.

Re: Objective-C basics - (Why NSNumber conforms to NSCopying protocol)

2016-08-11 Thread Sandor Szatmari
Quincey, Thanks for you additional thoughts... > On Aug 11, 2016, at 14:11, Quincey Morris > wrote: > > I didn’t realize that I was saying anything controversial. > >> On Aug 11, 2016, at 01:50 , Britt Durbrow >>

Re: Objective-C basics - (Why NSNumber conforms to NSCopying protocol)

2016-08-11 Thread Quincey Morris
I didn’t realize that I was saying anything controversial. On Aug 11, 2016, at 01:50 , Britt Durbrow wrote: > > Which, IMHO, means that *all* the values stored in the object must be the > same. > > By extension; [anObject hash] and [[anObject copy]

Re: Objective-C basics - (Why NSNumber conforms to NSCopying protocol)

2016-08-11 Thread Greg Weston
>> 2. The fact than an object is immutable does not (in general) mean that a >> copy can be represented by the same object reference. For example, an object >> that contained its own date of creation might be immutable, but a copy might >> have a different date, and therefore be a different

Re: Objective-C basics - (Why NSNumber conforms to NSCopying protocol)

2016-08-11 Thread Sandor Szatmari
Quincey, > On Aug 11, 2016, at 03:04, Quincey Morris > wrote: > >> On Aug 10, 2016, at 23:32 , Sasikumar JP wrote: >> >> what was the reason NSNumber conforms to NSCopying protocol. > > 1. It actually inherits conformance from its

Re: Objective-C basics - (Why NSNumber conforms to NSCopying protocol)

2016-08-11 Thread Dave
Also, beware the “copy” attribute on properties, this *always* creates an immutable copy. If you want to copy a Mutable Object you need to explicitly call mutableCopy, e.g. newObject.prop = [self.prop mutableCopy]; I mention this, because if you are writing copyWithZone methods then this will

Re: Objective-C basics - (Why NSNumber conforms to NSCopying protocol)

2016-08-11 Thread Sasikumar JP
Quincey, David, Thank you for the detailed explanation. Regards Sasikumar JP On 11 August 2016 at 12:34, Quincey Morris < quinceymor...@rivergatesoftware.com> wrote: > On Aug 10, 2016, at 23:32 , Sasikumar JP wrote: > > > what was the reason NSNumber conforms to NSCopying

Re: Objective-C basics - (Why NSNumber conforms to NSCopying protocol)

2016-08-11 Thread Dave
> Hmm… I’m not so sure that this is *quite* right… what if I want a copy of the > original object, with the same creation date? Not doing so could lead to some > strange pitfalls, depending on what is then done with the alleged “copy”, and > how it reacts to other methods (like -hash and

Re: Objective-C basics - (Why NSNumber conforms to NSCopying protocol)

2016-08-11 Thread Britt Durbrow
> On Aug 11, 2016, at 12:04 AM, Quincey Morris > wrote: > > 2. The fact than an object is immutable does not (in general) mean that a > copy can be represented by the same object reference. For example, an object > that contained its own date of creation

Re: Objective-C basics - (Why NSNumber conforms to NSCopying protocol)

2016-08-11 Thread Quincey Morris
On Aug 10, 2016, at 23:32 , Sasikumar JP wrote: > > what was the reason NSNumber conforms to NSCopying protocol. 1. It actually inherits conformance from its superclass, NSValue. 2. The fact than an object is immutable does not (in general) mean that a copy can be

Re: Objective-C basics - (Why NSNumber conforms to NSCopying protocol)

2016-08-11 Thread David Duncan
> On Aug 10, 2016, at 11:32 PM, Sasikumar JP 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

Objective-C basics - (Why NSNumber conforms to NSCopying protocol)

2016-08-11 Thread Sasikumar JP
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