Core Data Metadata
Core Data Metadata
- Subject: Core Data Metadata
- From: Ryan Britton <email@hidden>
- Date: Sun, 12 Mar 2006 10:39:07 -0800
I'm trying to implement a data store versioning system to handle
updates to the underlying object model for my application. I've had
no problem doing that, but I am having problems setting the version
information in the store's metadata. I've looked at the migrator
code provided in Core Recipes and implemented my solution much along
those lines, but the version attribute will not stick. The store I'm
using is a single application-wide SQLite store.
The relevant code snippet is:
- (void)setMetadata:(id)value forKey:(NSString *)key inStoreWithPath:
(NSString *)path inContext:(NSManagedObjectContext *)context
{
NSPersistentStoreCoordinator *coordinator = [context
persistentStoreCoordinator];
id store = [coordinator persistentStoreForURL:[NSURL
fileURLWithPath:path]];
if (store)
{
NSMutableDictionary *metadata = [[coordinator
metadataForPersistentStore:store] mutableCopy];
[metadata setObject:value forKey:key];
[coordinator setMetadata:metadata forPersistentStore:store];
//I can dump the metadata dictionary here and see all of the keys
that should be there
[metadata release];
}
else
{
[NSException raise:NSInternalInconsistencyException format:@"Unable
to load metadata for store: %@", path];
}
}
- (void)setNewVersion:(int)newVersion
{
NSString *sp = [ms_storePath stringByAppendingPathExtension:@"new"];
[self setMetadata:[NSNumber numberWithInt:newVersion]
forKey:kMyStoreVersionAttribute inStoreWithPath:sp
inContext:ms_newContext];
}
It seems that no matter what I try to set for the version, the
metadata only stores the two keys NSStoreType and NSStoreUUID. The
store is saved correctly (except for the metadata) and I am able to
load it in. The problem is that without the versioning information,
my code tries to convert it again and fails because the underlying
structure does not match the assumed version. Any ideas on what I
may be missing here? I've tried various values for the keys in case
something was reserved. I've tried both NSNumber and NSString for
the type of the object in case on certain data types were supported.
Nothing has seemed to work.Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden