• 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: Copying id
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Copying id


  • Subject: Re: Copying id
  • From: Graham Cox <email@hidden>
  • Date: Tue, 12 Aug 2008 12:33:23 +1000


On 12 Aug 2008, at 12:15 pm, Mike wrote:

Both the key and value for each key in the items in my array can be of any object type (id). The sorted key/value paid array class has to be able to make copies of the items in the arrays when it goes to sort them. Since the array class has to be generic to work with any kind of key, and any kind of object, I can't know the types beforehand. Since the array lass is generic and has to work for any objects, I can't assume that the objects implement NSCopying.


Why not just keep an array of sorted keys? Then you can use that to look up the item in the dictionary in the sorted order. Because NSDictionary requires an object of type id<NSCopying> as a key value, you can be sure that the key object supports NSCopying. Use NSDictionary's -allKeys method to get the keys, then sort them as you need. This is the conventional (i.e. expected) way to do this sort (pun intended) of thing.

hth,


cheers, Graham _______________________________________________

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: 
 >Copying id (From: Mike <email@hidden>)
 >Re: Copying id (From: Ken Thomases <email@hidden>)
 >Re: Copying id (From: Mike <email@hidden>)

  • Prev by Date: Re: Copying id
  • Next by Date: Re: Should I retain a variable returned from this accessor?
  • Previous by thread: Re: Copying id
  • Next by thread: Re: Copying id
  • Index(es):
    • Date
    • Thread