• 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: how do I put boolean variables in a NSDictionary?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how do I put boolean variables in a NSDictionary?


  • Subject: Re: how do I put boolean variables in a NSDictionary?
  • From: James Bucanek <email@hidden>
  • Date: Mon, 19 Jun 2006 13:09:07 -0700

Alan Smith wrote on Monday, June 19, 2006:

>Hi all,
>I want to put a bool in a NSDictionary to save in the NSUserDefaults.
>I've tried using this:
>
>NSDictionary *dict = [NSDictionary
>dictionaryWithObjectsAndKeys:@"Cheat", @"type", YES, @"compilation",
>nil];
>
>I get a SIGBUS error. It's because of the bool I know. I tried:

That's correct, because all of the parameters to dictionaryWithObjectsAndKeys must be object references. A BOOL is not an object reference, so you are passing an BOOL value as a pointer.

>NSDictionary *dict = [NSDictionary
>dictionaryWithObjectsAndKeys:@"Cheat", @"type", [NSNumber
>numberWithInt: 0], @"compilation", nil];

[NSNumber numberWithBool:NO] is more readable.

>And then:
>
>if ([[dict valueForKey: @"compilation"] boolValue])
>
>and that goes through. But that isn't as pretty or understandable as
>it could be.

That's as good as it's going to get. All primative type (int, char, BOOL, ...) must be wrapped in NSObjects to exist in a dictionary and then unwrapped again when you get them out agian.

--
James Bucanek
 _______________________________________________
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

References: 
 >how do I put boolean variables in a NSDictionary? (From: "Alan Smith" <email@hidden>)

  • Prev by Date: how do I put boolean variables in a NSDictionary?
  • Next by Date: Re: how do I put boolean variables in a NSDictionary?
  • Previous by thread: how do I put boolean variables in a NSDictionary?
  • Next by thread: Re: how do I put boolean variables in a NSDictionary?
  • Index(es):
    • Date
    • Thread