When I deal with this situation (and I have several times), I use the version . In other words, encode the version number along with the rest of your encoded data.
Even if you did not perform version control from the very beginning, this is not a problem, you can start now with version 1 and just consider the absence of version value as equivalent to version 0 .
How?
Save the version field in the encoded object. Using int or NSInteger for this field is probably best.
#define CURRENT_VERSION 1 #define MIN_VERSION_WITH_FEATURE_X 1 @implementation BiscuitTin - (id)initWithCoder:(NSCoder *)coder { self = [super init]; if (self) { ... int vers = [coder decodeIntForKey:@"version"]; if (vers >= MIN_VERSION_WITH_FEATURE_X) {
Whenever you add a new function that does not support backward compatibility, add CURRENT_VERSION , add a new constant MIN_VERSION_WITH_FEATURE_Y with the new integer value CURRENT_VERSION and another branch in the if expression in -initWithCoder: >.
This is a bit dirty, but I think the cost is backward compatible. (On the other hand, I think this method is quite self-documenting, and therefore it is easy to work with it when you return to it after a few months or years).
source share