Using NSUserDefaults for storing UISwitch state

前端 未结 2 914
梦如初夏
梦如初夏 2021-01-25 17:47

I am trying to persist the UISwitch state in my settings view of my application. Basically it is a UITableView and contains a few switches to get the u

相关标签:
2条回答
  • 2021-01-25 18:26

    Instead of using setObject:forKey: try using setBool:forKey:.

    [[NSUserDefaults standardUserDefaults] setBool:TRUE forKey:@"SyncAtStartup"];
    
    0 讨论(0)
  • 2021-01-25 18:42

    you can use following code;

    
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"SyncAtStartup"];
    BOOL test = [[NSUserDefaults standardUserDefaults] boolForKey:@"SyncAtStartup"];
    

    if you use following code, it will return YES;

    
    [[NSUserDefaults standardUserDefaults] setBool:TRUE forKey:@"SyncAtStartup"];
    BOOL test = [[NSUserDefaults standardUserDefaults] boolForKey:@"SyncAtStartup"];
    

    Just test above code;

    0 讨论(0)
提交回复
热议问题