Created
October 4, 2012 21:04
-
-
Save kastiglione/3836448 to your computer and use it in GitHub Desktop.
Setup a minimal NSIncrementalStore subclass for learning / experimenting with MacRuby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
framework 'CoreData' | |
# Create a minimal model | |
$thing = NSEntityDescription.alloc.init | |
$thing.name = 'Thing' | |
$model = NSManagedObjectModel.alloc.init | |
$model.entities = [$thing] | |
# Create the custom store class | |
class CustomStore < NSIncrementalStore | |
def loadMetadata(error) | |
self.metadata = {NSStoreTypeKey => 'CustomStore', NSStoreUUIDKey => '0123456789ABCDEF'} | |
true | |
end | |
end | |
# Register the custom store class | |
NSPersistentStoreCoordinator.registerStoreClass(CustomStore, forStoreType:'CustomStore') | |
# Create the store via a PSC | |
$coordinator = NSPersistentStoreCoordinator.alloc.initWithManagedObjectModel($model) | |
$custom_store_error = Pointer.new(:object) | |
$custom_store = $coordinator.addPersistentStoreWithType('CustomStore', configuration:nil, URL:nil, options:nil, error:$custom_store_error) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment