• 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: Integer as key in NSMutableDictionary
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Integer as key in NSMutableDictionary


  • Subject: Re: Integer as key in NSMutableDictionary
  • From: Martin Wierschin <email@hidden>
  • Date: Mon, 4 May 2009 15:19:50 -0700

Assume that:

NSMutableDictionary *result = [[NSMutableDictionary alloc] initWithCapacity:10];
NSInteger ID;


And I add objects to the dictionary:

		[result setObject:[NSArray arrayWithObjects: {... objects ...}
						   nil]

				   forKey:ID];

I am getting warnings when adding integers in the array and assigning
the integer ID as a key.

The Cocoa collection classes (eg: NSDictionary, NSArray, etc) always require object values, so you'll have to wrap your integer in an NSNumber like so:


	NSNumber* key = [NSNumber numberWithInteger:ID];
	[result setObject:whatever forKey:key];

Or, if you don't otherwise need to use the key, you can shorten that to:

	[result setObject:whatever forKey:[NSNumber numberWithInteger:ID]];

~Martin

_______________________________________________

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: 
 >Integer as key in NSMutableDictionary (From: Weydson Lima <email@hidden>)

  • Prev by Date: Re: drawing image
  • Next by Date: -[CALayer hitTest:] incorrect when embedding layer-backed NSView subclass inside NSScrollView
  • Previous by thread: Re: Integer as key in NSMutableDictionary
  • Next by thread: How to change the case of letters
  • Index(es):
    • Date
    • Thread