• 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: Simple NSMutableDictionary problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Simple NSMutableDictionary problem


  • Subject: Re: Simple NSMutableDictionary problem
  • From: Mark Allan <email@hidden>
  • Date: Tue, 12 Aug 2008 22:16:23 +0100

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@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: 
 >Simple NSMutableDictionary problem (From: Matt Keyes <email@hidden>)

  • Prev by Date: [Meet]: LA CocoaHeads Thursday August 14th, 7:30pm
  • Next by Date: [MEET] BYU CocoaHeads August 14th @ 7pm
  • Previous by thread: Simple NSMutableDictionary problem
  • Next by thread: Re: Simple NSMutableDictionary problem
  • Index(es):
    • Date
    • Thread