Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • How to add records into Firebase in iOS sdk?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 398
    Comment on it

    Hi Readers,

    Many developers use third party SDK for saving records into the Database, Firebase provides us this functionality. To add records into Firebase, please follow these steps:

    First of all, you need to create a reference to Firebase database like:

    [FIRApp configure];
    FIRDatabaseReference _fireBaseRef = [[FIRDatabase database] reference];

    Function, "configure" will configure your app according to GoogleService-Info.plist which you download while creating app into firebase console.

    _fireBaseRef is a reference of Firebase database which will be used to call it's functions.

    Now you need to add observer for child added into firebase. In Firebase there is no tabular data will be maintained. It can be seen in a tree hierarchy. You need to add child accordingly and update UI and other manipulation in observer method. Following is the observer method:

    [_firDBRefrence observeEventType:FIRDataEventTypeChildAdded withBlock:^(FIRDataSnapshot *snapshot) {
           // Do UI Changes and manipulation with snapshot

    As you can see it simply observe event type child added. Following is a method to add child into Firebase.

    NSMutableDictionary *mdata = [data mutableCopy];
        mdata[@"name"] = @"Mark";
        mdata[@"Number"] = @"987654321";
    [[[_firDBRefrence child:@"user"] childByAutoId] setValue:mdata];

    As you can see mdata is a dictionary which included values as name, number. Now with setValue we set mdata in user table with child name and number.

    Another thing you got notice is childByAutoId which is used for automatic created randomly generated id which Firebase created itself. You can change child id according to your requirement. 

    Hope this blog help to understand Firebase.

    Thanks for reading.



 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: