plist data after an update

374 views Asked by At

I've created a plist that stores all user's data in my app such as amount of coins, best score, some clothes from internal store and so on. And now, 1 day before release, I realized that after updating the app all user's data will be lost. Am I right?

If I'm not, how do plists work? Let's say, in version 1.0 of my app I have a plist consists of amount of user's coins. Then I decide to add amount of diamonds to my plist, so that plist in version 2.0 consists of coins AND diamonds. Default value for coins and diamonds is 0.

So, user downloads the 1 version, now he has 0 coins. He plays for a while and earns 100 coins. Then he updates the app to the 2 version. What happens to plist in this case? Will it be deleted, the new one added instead and user will have default 0 coins and 0 diamonds? Or it will not be updated at all? Or he'll still have 100 coins, but 0 diamonds?

All in all, I just want to know how other developers store user's data locally on device, without using external databases and so on.

P.S. That is how I create my plist:

    var paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as! String
    var path = paths.stringByAppendingPathComponent("UserInfo.plist")
    var data = NSMutableDictionary(contentsOfFile: path)

    var fileManager = NSFileManager.defaultManager()
    if (!(fileManager.fileExistsAtPath(path)))
    {
        var bundle : NSString = NSBundle.mainBundle().pathForResource("UserInfo", ofType: "plist")!
        fileManager.copyItemAtPath(bundle as String, toPath: path, error:nil)
    }
1

There are 1 answers

3
matt On

And now, 1 day before release, I realized that after updating the app all user's data will be lost. Am I right

No, not necessarily. If data is stored in user defaults or as a file saved into a nonvolatile region of the app's sandbox (such as the Documents directory), merely upgrading the app has no effect on it.