Title / Description
Code /** Returns the persistent store coordinator for the application. This implementation will create and return a coordinator, having added the store for the application to it. (The directory for the store is created, if necessary.) */ - (NSPersistentStoreCoordinator *)persistentStoreCoordinator { if (persistentStoreCoordinator) return persistentStoreCoordinator; NSManagedObjectModel *mom = [self managedObjectModel]; if (!mom) { NSAssert(NO, @"Managed object model is nil"); BSLog(@"%@:%s No model to generate a store from", [self class], _cmd); return nil; } NSFileManager *fileManager = [NSFileManager defaultManager]; NSString *applicationSupportDirectory = [self applicationSupportDirectory]; NSError *error = nil; if ( ![fileManager fileExistsAtPath:applicationSupportDirectory isDirectory:NULL] ) { if (![fileManager createDirectoryAtPath:applicationSupportDirectory withIntermediateDirectories:NO attributes:nil error:&error]) { NSAssert(NO, ([NSString stringWithFormat:@"Failed to create App Support directory %@ : %@", applicationSupportDirectory,error])); BSLog(@"Error creating application support directory at %@ : %@",applicationSupportDirectory,error); return nil; } } NSURL *url = [NSURL fileURLWithPath:[applicationSupportDirectory stringByAppendingPathComponent:@"storedata"]]; persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: mom]; // Persistent store migration Options NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil]; NSPersistentStore *persistentStore = [persistentStoreCoordinator addPersistentStoreWithType:NSXMLStoreType configuration:nil URL:url options:options error:&error]; if (!persistentStore){ [[NSApplication sharedApplication] presentError:error]; [persistentStoreCoordinator release], persistentStoreCoordinator = nil; return nil; } // Enable syncing on the store // [persistentStoreCoordinator setStoresFastSyncDetailsAtURL:[self URLForFastSyncDetails] forPersistentStore:persistentStore]; return persistentStoreCoordinator; }
Author
Highlight as C C++ CSS Clojure Delphi ERb Groovy (beta) HAML HTML JSON Java JavaScript PHP Plain text Python Ruby SQL XML YAML diff code