Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boolean inside property list (Simple!)

I'm writing a small application right now and I got problems while reading out a property list...

My exact question is: How can I read out a boolean from the property list? Or better how can I read out this boolean from a NSDictionary?

Thanks, mavrick3.

like image 311
Fabio Poloni Avatar asked Mar 03 '26 12:03

Fabio Poloni


2 Answers

The objects are stored as NSNumber objects, so to retrieve the BOOL you should use this method:

BOOL myBool = [someNSNumberObject boolValue];

To retrieve from a dictionary do something like this:

BOOl myBool = [[someDictionary objectForKey:@"someKey"] boolValue];

Documentation here: http://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/Reference/Reference.html#//apple_ref/occ/instm/NSNumber/boolValue

like image 160
theChrisKent Avatar answered Mar 06 '26 02:03

theChrisKent


Try storing the BOOL as a NSNumber ... then adding that to the Dictionary.

A simple example :

   BOOL answered = YES;
    NSNumber *answeredAsNumber = [NSNumber numberWithBool:answered];
    [dict setObject:answeredAsNumber forKey:@"isAnswered"];

    BOOL retrievedAnswered = [[dict objectForKey:@"isAnswered"] boolValue];
like image 26
MDMonty Avatar answered Mar 06 '26 03:03

MDMonty



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!