• 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: NSNumber numberWithBool ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSNumber numberWithBool ?


  • Subject: Re: NSNumber numberWithBool ?
  • From: Glen Low <email@hidden>
  • Date: Mon, 26 Jan 2004 12:59:54 +0800

Your code snippet will end up testing if such a dictionary value exists. you want:

if ([[tempDict valueForKey:@"status"] boolValue])

// Daniel Currie



On 2004 Jan 25, at 19:19, email@hidden wrote:

if i set a numberWithBool into a dictionary can i check it like this

if ([tempDict valueForKey:@"status"])

to see if its true or not?

That will be OK if you only need to check if the value is non-zero or not. I think boolValue tries to coerce the result to a BOOL, which means you can't tell whether the original number was an integer, something else or really a BOOL created with numberWithBool.

Instead of

if ([x boolValue])
// handle true
else
// handle false

The following is "more typesafe":

if ([x isEqualToValue: [NSNumber numberWithBool: YES]])
// handle true
else if ([x isEqualToValue: [NSNumber numberWithBool: NO]])
// handle false
else
// handle non-boolean value

I haven't been able to devise a neater solution, perhaps some of the more experienced members could figure it out. Also, apparently isEqual: doesn't work in this case and you have to use isEqualToValue:.

Back to the big picture question, if all the OP wanted was a dictionary of binary flags, you could look at NSSet.

Cheers, Glen Low


---
pixelglow software | simply brilliant stuff
www.pixelglow.com
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >NSNumber numberWithBool ? (From: email@hidden)
 >Re: NSNumber numberWithBool ? (From: Daniel Todd Currie <email@hidden>)

  • Prev by Date: ColorWell transparency
  • Next by Date: Re: ColorWell transparency
  • Previous by thread: Re: NSNumber numberWithBool ?
  • Next by thread: Re: NSNumber numberWithBool ?
  • Index(es):
    • Date
    • Thread