Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to wrap BOOL in NSValue

Having trouble wrapping a BOOL value in NSValue.

I tried this:

[NSValue valueWithPointer:[NSNumber numberWithBool:YES]]
like image 240
tiltem Avatar asked Aug 04 '11 18:08

tiltem


2 Answers

An NSNumber is an NSValue subclass. As such,[NSNumber numberWithBool:YES] is already wrapping it in an NSValue for you.

like image 106
Joshua Weinberg Avatar answered Oct 04 '22 03:10

Joshua Weinberg


Actually NSNumber is a heavier-weight descendant of NSValue. If you actually want to use an NSValue here's how you'd do that:

BOOL bool_value = YES;
[NSValue valueWithBytes:&bool_value objCType:@encode(BOOL)]
like image 34
jasonjwwilliams Avatar answered Oct 04 '22 03:10

jasonjwwilliams