Skip to content
/ FireData Public
forked from Manoj85/FireData

Seamlessly integrate Firebase with Core Data

License

Notifications You must be signed in to change notification settings

mme/FireData

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FireData

FireData seamlessly integrates Core Data with Firebase.

Usage

Include both Firebase and FireData in your application.

#import <Firebase/Firebase.h>
#import <FireData/FireData.h>

Initialize an instance of FireData

FireData *firedata = [[FireData alloc] init];

Listen for changes from the default managed object context

[firedata observeManagedObjectContext:self.managedObjectContext];

Create a new managed object context to write changes from Firebase; set its parent to the default managed object context.

NSManagedObjectContext *writingContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];
[writingContext setParentContext:self.managedObjectContext];
[firedata setWriteManagedObjectContext:writingContext withCompletionBlock:^(NSManagedObjectContext *context) {
    NSError *error = nil;
    if ([context save:&error]) {
        if (![self.managedObjectContext save:&error]) {
            NSLog(@"Error saving: %@", error);
        }
    } else {
        NSLog(@"Error saving: %@", error);
    }
}];

Get a reference to Firebase

Firebase *firebase = [[Firebase alloc] initWithUrl:@"https://EXAMPLE.firebaseio.com/"];

Link the Core Data and Firebase references that are to be synced

[firedata linkCoreDataEntity:@"Book" withFirebase:[firebase childByAppendingPath:@"books"]];

Check the existing data in Firebase

[firebase observeSingleEventOfType:FEventTypeValue withBlock:^(FDataSnapshot *snapshot) {
    // If Firebase is empty then replace with the data from Core Data
    if (snapshot.value == [NSNull null]) {
        [firedata replaceFirebaseFromCoreData];
    }

    // Start observing changes between Core Data and Firebase
    [firedata startObserving];
}];

Hold on to FireData

self.firedata = firedata;

Example Application

  • CoreDataBooks sample application that has been updated to support Firebase using FireData.

Known Issues

  • Firebase does not currently persistent offline changes to disk. Full offline support backed by disk will be coming in the future.[1]

License

MIT.

[1] https://groups.google.com/d/msg/firebase-talk/lVFOh9Wqwog/FvqWiiuP-_MJ

About

Seamlessly integrate Firebase with Core Data

Resources

License

Stars

Watchers

Forks

Packages

No packages published