Re: Adding items to NSMutableDictionary
Re: Adding items to NSMutableDictionary
- Subject: Re: Adding items to NSMutableDictionary
- From: Nik Bauman <email@hidden>
- Date: Wed, 29 Jun 2005 13:05:12 -0700
Ondra,
Your right, it turns out I was simply using [properties objectForKey:@"word"]
when I should have used [[properties objectForKey:@"word"] intValue]
Thanks for the help.
-N
On 6/29/05, Ondra Cada <email@hidden> wrote:
> 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