我想将 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];
}
提前致谢。