Question

I want to add versioning to my UIDocument local storage setup. In each of my classes that needs to be stored locally, I overwrite encodeWithCoder: and initWithCoder: like so:

#define kLovelyString @"LovelyString"

- (void)encodeWithCoder:(NSCoder *)aCoder
{
    [aCoder encodeObject:self.lovelyString forKey:kLovelyString];
}

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];
    if (self)
    {
        self.lovelyString = [aDecoder decodeObjectForKey:kLovelyString];
    }
    return self;
}

I'd like to prepare for different versions of my model by adding versioning support. Should I simply add [aCoder encodeInteger:version] to encodeWithCoder: and create if/else statements in initWithCoder: to determine how to handle each version?

As far as I can tell, NSFileVersion is not helpful here.

Was it helpful?

Solution

As @Dima said, this is the standard implementation. Bonus -- Best to have a global version stored in your Database Access Layer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top