In version 1.0 i am using NSMutableArray and inside that i am storing NSNumbers like
NSMutableArray *myArray;
for(int i= 0 ; i < 10 ; i++)
[myArray addObject:[NSNumber numberWithInt:i]];
For storing my gameStatus.
In Next version(1.1) I want to update myArray like(by storing dictionary inside it)…
NSMutableArray *myArray;
for(int i= 0 ; i < 10 ; i++)
{
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setValue:number forKey:@"index"];
[dict setValue:[NSNumber numberWithBool:NO] forKey:@"isValid"];
[myArray addObject:dict];
[dict release];
}
My problem is how to provide compatibility for previous version 1.0.
Thanks in advance.
Updated : I am supporting Version 1.1 as shown below, is it ok.
//Version 1.1 support
//Read myArray
if( [myArray count] > 0)
{
if( ![[myArray objectAtIndex:0] isKindOfClass:[NSMutableDictionary class]])
{
for( NSNumber *number in myArray)
{
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setValue:number forKey:@"index"];
[dict setValue:[NSNumber numberWithBool:NO] forKey:@"isValid"];
[dict release];
}
}
}
I assume your point is that you’re saving these to disk at some point, and you want to handle loading them after upgrade. There are tons of ways to handle this, but here’s what I would recommend for this specific case:
This scales well when you get to v1.2 and change your data again. You will need to keep around your “how to read v1.0” code more or less forever (or at least until you completely drop support for upgrading from 1.0), but that’s true in any case.