• 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: Adding items to NSMutableDictionary
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Adding items to NSMutableDictionary


  • Subject: Re: Adding items to NSMutableDictionary
  • From: Ondra Cada <email@hidden>
  • Date: Wed, 29 Jun 2005 21:21:14 +0200

Ahem... not quite...

On 29.6.2005, at 20:25, j o a r wrote:

You're just using the wrong setter method. You should be using "- [NSMutableDictionary setObject:forKey:]"

Though the setObject:forKey: message is naturally the more proper one in such case, it nevertheless should work through KVC too.


And, it does:

7 /tmp> <q.m
#import <Foundation/Foundation.h>
int main() {
[NSAutoreleasePool new];
id d=[NSMutableDictionary new];
[d setValue:[NSNumber numberWithInt:1] forKey:@"number"];
[d setValue:[NSArray array] forKey:@"array"];
[d setValue:[NSUserDefaults standardUserDefaults] forKey:@"defaults"];
for (id o,en=[d keyEnumerator];(o=[en nextObject]);)
NSLog(@"%@: %@: %@",o,[[d objectForKey:o] class],[d objectForKey:o]);
return 0;
}
8 /tmp> cc -std=gnu99 -Wall -framework Foundation q.m && ./a.out
2005-06-29 21:19:08.299 a.out[2346] defaults: NSUserDefaults: <NSUserDefaults: 0x504e00>
2005-06-29 21:19:08.300 a.out[2346] number: NSCFNumber: 1
2005-06-29 21:19:08.300 a.out[2346] array: NSCFArray: ()
9 /tmp>


Okay, this is probably very very simple, but for some reason I can't figure out how to add an entry into a dictionary with any data type other than an NSString. I assume that every data type available in the Property List Editor (string, dictionary, array, number, boolean, date) is supported but Every time I have a value in number or boolean form and use code like this :

NSMutableDictionary *properties = [[NSMutableDictionary alloc] init];
[properties setValue:[NSNumber numberWithInt: integer ] forKey:@"word"];


it never send the right value. The only thing I'm ever successful at is using NSStrings.

How can I input other (I assume supported) data types into dictionaries?

Therefore, there's bound to be another problem in your code, Nik. --- Ondra Čada OCSoftware: email@hidden http://www.ocs.cz private email@hidden http://www.ocs.cz/oc


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Adding items to NSMutableDictionary
      • From: Nik Bauman <email@hidden>
    • Re: Adding items to NSMutableDictionary
      • From: Ondra Cada <email@hidden>
References: 
 >Adding items to NSMutableDictionary (From: Nik Bauman <email@hidden>)
 >Re: Adding items to NSMutableDictionary (From: j o a r <email@hidden>)

  • Prev by Date: Re: Services Menu? Deprecated?
  • Next by Date: Re: Adding items to NSMutableDictionary
  • Previous by thread: Re: Adding items to NSMutableDictionary
  • Next by thread: Re: Adding items to NSMutableDictionary
  • Index(es):
    • Date
    • Thread