• 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: Objective-C coding question..
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Objective-C coding question..


  • Subject: Re: Objective-C coding question..
  • From: Wyatt Webb <email@hidden>
  • Date: Wed, 21 Jul 2010 16:41:49 -0700

On Jul 21, 2010, at 4:29 PM, Clark Williams wrote:

Now the question. How do I reference the BOOL?
If I try the following:
    BOOL widget = @(BOOL *)[temp objectForKey:@"strKey4"];
I get a bad value.
If I try anything with the RHS set to:
(BOOL*)[temp objectForKey:@"strKey4"];
I get a warning: invalid receiver type 'BOOL *'

I also tried BOOL widget = [temp boolValueForKey:@"strKey4"];

I got a warning saying: 'NSDictionary' may not respond to '-boolForKey:'

BTW all the other key values are passed correctly except the BOOL.

So...flummoxed!
Suggestions?


 Clark,

A BOOL is just a typedef to a signed char, so it's a built-in type. For integers, doubles, floats, chars, etc. you should expect the object to be an NSNumber*. So you'd do something like this:

NSNumber* widget = [temp objectForKey:@"strKey4"];

then, you can ask the NSNumber for a bool value like so:

BOOL widgetFlag = [widget boolValue];

So, of course, you could do this in one line like this:

BOOL widget = [[temp objectForKey:@"strKey4"] boolValue];

You're getting the warning for the "boolForKey:" call because that's only for NSUserDefaults, not an NSDictionary.

Hope that helps,

Wyatt
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Objective-C coding question.. (From: Clark Williams <email@hidden>)

  • Prev by Date: Re: Objective-C coding question..
  • Next by Date: Re: Interface Builder 3.2.3 : Can't focus on subviews in some tab views
  • Previous by thread: Re: Objective-C coding question..
  • Next by thread: Errors when using SenTestingKit
  • Index(es):
    • Date
    • Thread