简体   繁体   中英

Create plist first in Xcode?

I've read conflicting views on this

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

If I want to use a plist to hold my tile map objects game data, do I have to create a plist with xcode first? and then update that? or do I not need to do that and I can just create it from scratch with code when the game runs?

If I don't have to create one with xcode first, what would be the benefit of doing that?

The code from your link is useful if you want some default data in the property list when the application is started for the first time.

If you don't need default data, don't have to create a property list in Xcode and include it in your application.

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];
}

Now you can add/modify/remove items in plistDict and save it later.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM