BOOL issue in Objective-C -
when i'm trying bool dictionary, get:
bool istrue = [somedict objectforkey: @"istrue"]; i get:
initialization makes integer pointer without cast i set dictionary doing this:
self.somedict = [[nsmutabledictionary alloc] initwithobjectsandkeys: self.istrue, @"istrue", nil]; any ideas?
use:
bool istrue = [[somedict objectforkey:@"istrue"] boolvalue]; the way store bool in nsdictionary box in nsnumber object. bool primitive, , dictionary holds objects.
similarly, store bool in dictionary, use:
[somedict setobject:[nsnumber numberwithbool:istrue] forkey:@"istrue"]; edit: (in response comment)
there 2 ways of representing @property. 1 declare ivar bool, , other declare nsnumber.
for first case, ivar is: bool istrue;, , property @property bool istrue; (i'm ignoring naming conventions, obviously).
for nsnumber, ivar is: nsnumber * istrue; , property @property (nonatomic, retain) nsnumber * istrue;. if go route, might want provide second setter method (setistruebool or something) allows pass in yes or no, , boxing yourself. otherwise calls have boxing themselves.
i'd go option #1, depends on class's purpose was.
Comments
Post a Comment