• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Objective-C basics - (Why NSNumber conforms to NSCopying protocol)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Subject: Re: Objective-C basics - (Why NSNumber conforms to NSCopying protocol)
  • From: Britt Durbrow <email@hidden>
  • Date: Thu, 11 Aug 2016 16:33:47 -0700

> On Aug 11, 2016, at 3:32 PM, Sandor Szatmari <email@hidden> 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 -isEqual:

It’s OK, for example, to use mutable objects as the values in an NSDictionary; but can be hazardous when used as the keys.

NSArrays have no problem with mutable objects for most of their methods, because they are based on index positions.

NSSets can hiccup quite badly if something mutates unexpectedly.

NSObject, by itself, implements pointer hashing (i.e, -hash is derived from the value of self); and pointer comparison (a basic NSObject is only equal to itself); so if you don’t override -hash and -isEqual: than any mutability your objects might have won’t be visible to the collection objects.

> 2. You really need to be overtly aware of these details when designing classes and implementing -hash and -isEqual:

And when using them in collections, even if you are just using the stock Cocoa value classes!

:-)
_______________________________________________

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


References: 
 >Objective-C basics - (Why NSNumber conforms to NSCopying protocol) (From: Sasikumar JP <email@hidden>)
 >Re: Objective-C basics - (Why NSNumber conforms to NSCopying protocol) (From: Quincey Morris <email@hidden>)
 >Re: Objective-C basics - (Why NSNumber conforms to NSCopying protocol) (From: Britt Durbrow <email@hidden>)
 >Re: Objective-C basics - (Why NSNumber conforms to NSCopying protocol) (From: Quincey Morris <email@hidden>)
 >Re: Objective-C basics - (Why NSNumber conforms to NSCopying protocol) (From: Sandor Szatmari <email@hidden>)
 >Re: Objective-C basics - (Why NSNumber conforms to NSCopying protocol) (From: Quincey Morris <email@hidden>)
 >Re: Objective-C basics - (Why NSNumber conforms to NSCopying protocol) (From: Sandor Szatmari <email@hidden>)

  • Prev by Date: Re: Objective-C basics - (Why NSNumber conforms to NSCopying protocol)
  • Next by Date: Re: Objective-C basics - (Why NSNumber conforms to NSCopying protocol)
  • Previous by thread: Re: Objective-C basics - (Why NSNumber conforms to NSCopying protocol)
  • Next by thread: Re: Objective-C basics - (Why NSNumber conforms to NSCopying protocol)
  • Index(es):
    • Date
    • Thread