我想将bool属性保存到我的文件中,我认为这样做是野蛮的.我必须检查我的属性,然后将字符串添加到NSMutableArray.我可以检查属性名称,状态/值然后保存到文件吗?或者也许我应该使用XML文件?但仍然为了有效使用我应该得到属性名称和州/值.
你能给我一些建议吗?
-(void) saveSettings
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"settings" ofType:@""];
if (music)
{
[correctSettingArray removeObjectAtIndex:0];
[correctSettingArray addObject:@"music = 1"];
}
else
{
[correctSettingArray removeObjectAtIndex:0];
[correctSettingArray addObject:@"music = 0"];
}
if (sfx)
{
[correctSettingArray removeObjectAtIndex:1];
[correctSettingArray addObject:@"sfx = 1"];
}
else
{
[correctSettingArray removeObjectAtIndex:0];
[correctSettingArray addObject:@"sfx = 0"];
}
if (vibration)
{
[correctSettingArray removeObjectAtIndex:0];
[correctSettingArray addObject:@"vibration = 1"];
}
else
{
[correctSettingArray removeObjectAtIndex:0];
[correctSettingArray addObject:@"vibration = 0"];
}
[correctSettingArray writeToFile:path atomically:true];
}
Run Code Online (Sandbox Code Playgroud)
提前致谢.