How to check a bool setting in my iphone app

Posted by dusk on Stack Overflow See other posts from Stack Overflow or by dusk
Published on 2010-05-06T23:23:16Z Indexed on 2010/05/06 23:28 UTC
Read the original article Hit count: 185

Filed under:
|
|

I have a setting in Root.plist with Key = 'latestNews' of type PSToggleSwitchSpecifier and DefaultValue as a boolean that is checked. If I understand that correctly, it should = YES when I pull it in to my code. I'm trying to check that value and set an int var to pass it to my php script. What is happening is that my boolean is either nil or NO and then my int var = 0. What am I doing wrong?


    int latestFlag;

    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];

    BOOL latestNews = [prefs boolForKey:@"latestNews"];

    if (latestNews)
        latestFlag = 1;
    else
        latestFlag = 0;

    NSString *urlstr = [[NSString alloc] initWithFormat:@"http://www.mysite.com/folder/iphone-test.php?latest=%d", latestFlag];
    NSURL *url = [[NSURL alloc] initWithString:urlstr];

    //these are auto-released
    NSString *ans = [NSString stringWithContentsOfURL:url];
    NSArray *listItems = [ans componentsSeparatedByString:@","];

    self.listData = listItems;

    [urlstr release];
    [url release];

© Stack Overflow or respective owner

Related posts about iphone

Related posts about nsuserdefaults