Its not possible for a un-wrappered core data file
In the event you attempt to trap NSSaveAsOperation
and do a migrate on the persistent store for that enum the construction of the ...-journal
file will fail to create as its outside the sandbox.
-(void)saveToURL:(NSURL *)url ofType:(NSString *)typeName forSaveOperation:(NSSaveOperationType)saveOperation completionHandler:(void (^)(NSError *))completionHandler
{
NSLog(@" save op = %ld to %@ ",saveOperation,url);
NSURL *targeturl = url;
if(saveOperation == NSSaveAsOperation)
{
//migrate pstore
NSPersistentStore *store = [self.managedObjectContext.persistentStoreCoordinator.persistentStores lastObject];
if (store)
{
NSMutableDictionary *opts = [NSMutableDictionary dictionary];
[opts setValue:[NSNumber numberWithBool:YES] forKey:NSInferMappingModelAutomaticallyOption];
[opts setValue:[NSNumber numberWithBool:YES] forKey:NSMigratePersistentStoresAutomaticallyOption];
NSError *error = NULL;
NSPersistentStore *newstore = [self.managedObjectContext.persistentStoreCoordinator migratePersistentStore:store toURL:url options:opts withType:store.type error:&error];
if(newstore == nil)
{
NSLog(@"migration error %@",[error localizedDescription]);
}
self.fileURL = url;
}
}
[super saveToURL:targeturl ofType:typeName forSaveOperation:saveOperation completionHandler:completionHandler];
}
So we need to wrapper the file in a bundle/folder which is non-trivial using the NSPersistentDocument
framework.
Heres waiting for NSManagedDocument
(thats a wishing well API)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…