Skip to content

Instantly share code, notes, and snippets.

@drnic
Created January 1, 2009 01:35
Show Gist options
  • Save drnic/42172 to your computer and use it in GitHub Desktop.
Save drnic/42172 to your computer and use it in GitHub Desktop.
# 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 folder for the store is created,
# if necessary.)
def persistentStoreCoordinator
if @persistentStoreCoordinator
return @persistentStoreCoordinator
end
error = Pointer.new_with_type('@')
fileManager = NSFileManager.defaultManager
applicationSupportFolder = self.applicationSupportFolder
if !fileManager.fileExistsAtPath(applicationSupportFolder, isDirectory:nil)
fileManager.createDirectoryAtPath(applicationSupportFolder, attributes:nil)
end
url = NSURL.fileURLWithPath(applicationSupportFolder.stringByAppendingPathComponent("Grokking Recipes.xml"))
options = { NSMigratePersistentStoresAutomatically: NSNumber.numberWithBool(true)}
@persistentStoreCoordinator = NSPersistentStoreCoordinator.alloc.initWithManagedObjectModel(self.managedObjectModel)
if !@persistentStoreCoordinator.addPersistentStoreWithType(NSXMLStoreType, configuration:nil, URL:url, options:options, error:error)
NSApplication.sharedApplication.presentError(error[0])
end
return @persistentStoreCoordinator
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment