• 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: Storing objects in NSMutableDictionary
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Storing objects in NSMutableDictionary


  • Subject: Re: Storing objects in NSMutableDictionary
  • From: Geoffrey Holden <email@hidden>
  • Date: Sat, 14 Aug 2010 09:08:12 +0100

The class object is 'message' and its key 'messageID' is an NSString. If I set the object to be an NSString (or NSArray or NSDictionary), the dictionary stores it just fine. It just won't store 'message'.

messageID is, in reality, generated elsewhere. But you could imagine it to be NSString* messageID with a value of, say, @"FirstDocument". Messenger refers to a nib file with which message is initialized. And I know that my method name (initWithApp) might be a bit rubbish, but I can always refactor later!

NewMessage* message = [[NewMessage alloc] initWithApp:@"Messenger" :self];
[currentMessages setObject:message forKey:messageID];




On 13 Aug 2010, at 21:22, Greg Parker wrote:

On Aug 13, 2010, at 1:09 PM, Geoffrey Holden wrote:
Is it possible to store a class object in NSMutableDictionary?

Class objects cannot be used as dictionary keys, because NSDictionary copies its keys and class objects can't be copied. Class objects can be used as dictionary values.



[currentMessages setObject:message forKey:messageID];

Is `messageID` supposed to be the class object? If so, that won't work. One solution is to use NSString class names for the dictionary keys, and use NSClassFromString() and NSStringFromClass() to convert.



-- Greg Parker email@hidden Runtime Wrangler



_______________________________________________

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


  • Follow-Ups:
    • Re: Storing objects in NSMutableDictionary
      • From: "email@hidden" <email@hidden>
    • Re: Storing objects in NSMutableDictionary
      • From: Kyle Sluder <email@hidden>
References: 
 >Storing objects in NSMutableDictionary (From: Geoffrey Holden <email@hidden>)
 >Re: Storing objects in NSMutableDictionary (From: Greg Parker <email@hidden>)

  • Prev by Date: Re: Recursive file remove
  • Next by Date: Re: Storing objects in NSMutableDictionary
  • Previous by thread: Re: Storing objects in NSMutableDictionary
  • Next by thread: Re: Storing objects in NSMutableDictionary
  • Index(es):
    • Date
    • Thread