首先在 Xcode 中创建 plist



我读过关于这个的相互矛盾的观点

http://ipgames.wordpress.com/tutorials/writeread-data-to-plist-file/

如果我想使用 plist 来保存我的磁贴地图对象游戏数据,我是否必须先使用 xcode 创建一个 plist? 然后更新它? 还是我不需要这样做,我可以在游戏运行时用代码从头开始创建它?

如果我不必先用 xcode 创建一个,这样做有什么好处?

如果您希望在

首次启动应用程序时在属性列表中显示一些默认数据,则链接中的代码非常有用。

如果您不需要默认数据,则不必在 Xcode 中创建属性列表并将其包含在应用程序中。

NSString *path = ... // path to plist file in Documents directory
NSMutableDictionary *plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
if (plistDict == nil) {
    // No plist present (or invalid contents), start with empty dictionary:
    plistDict = [[NSMutableDictionary alloc] init];
}

现在,您可以在plistDict中添加/修改/删除项目,并在以后保存。

最新更新