FirebaseParcelKit integrates Core Data with Google Firebase Realtime Database. It is almost entirely based on Jonathan Younger's ParcelKit which was for the excellent but now-deprecated Dropbox Datastore.
FirebaseParcelKit can be added to a project using CocoaPods. We also distribute a framework build.
// Podfile
pod 'FirebaseParcelKit', :git => "https://github.com/andygeers/FirebaseParcelKit"
and
pod install
- Open the ParcelKit.xcodeproj project
- Select the “Framework” scheme
- Build (⌘B) the Framework
- Open the Products section in Xcode, right click “libParcelKit.a”, and select “Show in Finder”
- Drag and drop the “ParcelKit.framework” folder into your iPhone/iPad project
- Edit your build settings and add
-ObjC
to “Other Linker Flags”
Include FirebaseParcelKit in your application.
#import <ParcelKit/ParcelKit.h>
Initialize an instance of the FirebaseParcelKit sync manager with the Core Data managed object context that we should be used for listening for changes from and writing changes to - as well as the globally unique user ID from Firebase Auth:
PKSyncManager *syncManager = [[PKSyncManager alloc] initWithManagedObjectContext:self.managedObjectContext userId:self.userId];
Associate the Core Data entity names with the corresponding Firebase database tables.
[syncManager setTable:@"books" forEntityName:@"Book"];
Start observing changes from Core Data and Firebase.
[syncManager startObserving];
Hold on to the sync manager reference.
self.syncManager = syncManager;
ParcelKit requires two extra attribute inside your Core Data model.
- syncID with the type String. The Indexed property should also be checked.
- isSynced with the type Boolean. The Indexed property should also be checked.
- remoteSyncTimestamp with the type Int64. The Optional property should be checked and the default should be unchecked.
Make sure you add these attribute to each entity you wish to sync.
Alternative attribute names may be specifed by changing the syncAttributeName, isSyncedAttributeName and remoteTimestampAttributeName properties on the sync manager object.
- ParcelKit Reference documentation
- Toado - Simple task manager demonstrating the integration of Core Data and Dropbox using ParcelKit.
- iOS 7.0 or higher
- Google Firebase SDK 3.1.2 or higher
- Xcode 5 or higher
MIT.