Skip to Content

NSMutableDictionary writeToFile__--__ atomically__--__ - Example

Posted on
UISwitch *effectSoundOnOff = [self getChildByTag:SWITCH1];
UISwitch *flipOnOff = [self getChildByTag:SWITCH2];

NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
  
[dic setObject:([effectSoundOnOff isOn] ? @"YES" : @"NO") forKey:@"effectSound"];
[dic setObject:([flipOnOff isOn] ? @"YES" : @"NO") forKey:@"flip"];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fileName = [documentsDirectory stringByAppendingPathComponent:@"options.data"];

[dic writeToFile:fileName atomically:YES];