• 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: NSMutableDictionary drives me mad.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSMutableDictionary drives me mad.


  • Subject: Re: NSMutableDictionary drives me mad.
  • From: Andy Lee <email@hidden>
  • Date: Tue, 10 Mar 2009 14:54:41 -0400

On Mar 10, 2009, at 2:33 PM, Тимофей Даньшин wrote:
I am writing a method for searching for the longest common substring. The idea is to store the pieces of that LCS in an NSMutableDictionary with TMIntWrappers as keys and NSMutableStrings as values.
Now, TMIntWrapper is the class i created for wrapping ints into objects. It stores an int, gives access to it via the .value property, adopts the NSCopying protocol and implements the -(BOOL) isEqual: (id) object method.

Does TMIntWrapper also implement -hash? And is the .value property mutable?


<http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Protocols/NSObject_Protocol/Reference/NSObject.html >
If two objects are equal (as determined by the isEqual: method), they must have the same hash value. This last point is particularly important if you define hash in a subclass and intend to put instances of that subclass into a collection.

If a mutable object is added to a collection that uses hash values to determine the object’s position in the collection, the value returned by the hash method of the object must not change while the object is in the collection. Therefore, either the hash method must not rely on any of the object’s internal state information or you must make sure the object’s internal state information does not change while the object is in the collection. Thus, for example, a mutable dictionary can be put in a hash table but you must not change it while it is in there. (Note that it can be difficult to know whether or not a given object is in a collection.)

And, as others have asked, can you use NSNumber?

--Andy

_______________________________________________

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: 
 >NSMutableDictionary drives me mad. (From: Тимофей Даньшин <email@hidden>)

  • Prev by Date: Re: NSMutableDictionary drives me mad.
  • Next by Date: Re: Garbage collected and non-garbage collected
  • Previous by thread: Re: NSMutableDictionary drives me mad.
  • Next by thread: Intercepting events from a control
  • Index(es):
    • Date
    • Thread