(faulting) • Need more info? Watch Daniel Eggert explain it: http://www.uikonf.com/speakers/daniel_eggert.html WHAT IS CORE DATA? SQLite XML CouchDB ManagedObjectContext(s) PersistentStore(s) PSC Model
or CouchbaseLite • Persistence to CouchDB, TouchDB or CouchbaseLite • CouchbaseLite not yet feature complete • Creates views for to-many relationships • Uses those in fetches to speed things up
views, etc. • Call -setMetadata:, eventually generate the Store-UUID • -executeRequest:withContext:error: • Central method for accessing the DB • NSSaveRequestType → insert / update / delete the data into DB • NSFetchRequestType → query the DB depending on resultType • Parses NSPredicate and tries to use the to-many views for relationships, ...
the properties into NSIncrementalStoreNode • -newValueForRelationship:forObjectWithID:withContext:error: • to-many: query the to-many-view and return NSManagedObjectIDs • to-one: load the document and returns either the NSManagedObjectID or NSNull • -obtainPermanentIDsForObjects:error: • generates a reference-object from a UUID and the entity name and • calls -newObjectIDForEntity:referenceObject: • ... plus many helper methods
• Used by a small test group using iVocabulary • Users could collaborate via filtered replications • Slow when re-creating views • Sometimes 10+ seconds when fetching data • Slow in some fetches • In worst case needs to iterate all documents
libCouchbaseIncrementalStore.a • for TouchDB: libCouchCocoa.a, libTouchDB.a • for CouchDB: libCouchCocoa.a • for CouchbaseLite: libCouchbaseLite.a • + some other dependencies
before first use (adds revision ID): [CBCouchCocoaIncrementalStore updateManagedObjectModel:mom]; • Change store type to: [CBCouchCocoaIncrementalStore type] • Change store URL to: storeURL = [directoryURL URLByAppendingPathComponent: @"<foldername>.touchdb/<database-name>"];
[store replicateWithURL:remoteURL exclusively:YES]; • But: the persistent store doesn‘t know about the contexts • Your code needs to tell the contexts about changes • handle kCBISObjectHasBeenChangedInStoreNotification • create a NSManagedObjectContextDidSaveNotification for merging
work out of the box, though) • CBCouchbaseIncrementalStore: https://github.com/chbeer/CBCouchbaseIncrementalStore • CouchDB: http://couchdb.apache.org • TouchDB: http://touchdb.org • CouchCocoa: https://github.com/couchbaselabs/CouchCocoa • NSHipster on NSIncrementalStore: http://nshipster.com/nsincrementalstore/