• 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
Dictionary not returning objects
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Dictionary not returning objects


  • Subject: Dictionary not returning objects
  • From: Markus Spoettl <email@hidden>
  • Date: Sun, 15 Apr 2012 20:01:19 +0200

Hello,

I seem to be having an acute case of brain blockage, I can't figure out what I'm doing wrong with a simple thing I've done a thousand times.

I have an NSDictionary that contains, well, objects. When I call -objectForKey: I get nil for keys that are definitely in there.

The dictionary gets constructed like this:

  [NSDictionary dictionaryWithObjectsAndKeys:
      kUnitsKey, [NSNumber numberWithDouble:units],
      kValueKey, [NSNumber numberWithDouble:value],
      kIsMetricKey, [NSNumber numberWithBool:isMetric],
      nil];

This is later used elsewhere, where it seems to arrive intact.

  po dict

outputs this:

------ Debugger output ------
Printing description of dict:
{
    1 = kIsMetricKey;
    "3.852019958611236" = kValueKey;
    200 = kUnitsKey;
}
---- Debugger output end ----

kUnitsKey, kValueKey and kIsMetricKey are declared in a separate header as

  extern NSString *kUnitsKey;
  extern NSString *kValueKey;
  extern NSString *kIsMetricKey;

and defined in a .m as

  NSString *kUnitsKey = @"kUnitsKey";
  NSString *kValueKey = @"kValueKey";
  NSString *kIsMetricKey = @"kIsMetricKey";

  po kUnitsKey

yields

   (NSString *) $11 = 0x0000000100323f68 kUnitsKey

accordingly for the other keys. Yet

   [dict objectForKey:kUnitsKey]

returns nil

   po [dict objectForKey:kUnitsKey]

yields

   (id) $10 = 0x0000000000000000 <nil>

The keys are unique, there are no duplicates with different values elsewhere.

I'm using Xcode 4.3.2 on Lion 10.7.3, fully updated, this is a Mac OS X, project compiled with Apple LLVM 3.1 debugged using LLDB. Even tried LLVM GCC4.2 and I did a full clean and recompile, same result.

So it's me. What's wrong?

Thanks for any pointers!

Regards
Markus
--
__________________________________________
Markus Spoettl
_______________________________________________

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

  • Follow-Ups:
    • Re: Dictionary not returning objects
      • From: Seth Willits <email@hidden>
    • Re: Dictionary not returning objects
      • From: Scott Ribe <email@hidden>
  • Prev by Date: Re: Bookmark alias files v. Finder alias files
  • Next by Date: Re: Bookmark alias files v. Finder alias files
  • Previous by thread: Re: Xcode warns about missing protocol definition, even though @protocol is used
  • Next by thread: Re: Dictionary not returning objects
  • Index(es):
    • Date
    • Thread