At 9:12 pm +0000 12/08/2008, Matt Keyes wrote:
How do I have an int as a value in a NSMutableDictionary object?

for example:

NSMutableDictionary *myDictionary = [NSMutableDictionary alloc];

int i = 1;

[myDictionary setValue:1 forKey:@"One"];

This causes a compiler warning:

"warning: passing argument 1 of 'setValue:forKey:' makes pointer from integer without a cast"

It seems like (b/c the type is "id" for the first param) that NSMutableDictionary wants a pointer. Well, how do I give it just a plain integer copy without having the compiler yell at me? I have been banging my head on my desk over this silly little thing.

Also, how do I define a non-mutable dictionary of a particular size? There is no dictionaryWithCapacity function that I can find in the non-mutable version. All the examples I can find are not practical (i.e. hardcoding a dictionary at its creation with random values like @"One", @"Two", etc.).

Thanks!
Matt

You need to pass it an NSNumber.  Do something like this:

[myDictionary setObject:[NSNumber numberWithInt:1] forKey:@"one"];


Mark

_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to