Reputation: 221
Im trying to retrieve information from my firebase. Heres what the data looks .
Every time i run this i receive null in the log.
Firebase *ref = [[Firebase alloc] initWithUrl: @"https://sizzling-inferno-255.firebaseio.com/"];
[ref observeEventType:FEventTypeChildAdded withBlock:^(FDataSnapshot *snapshot) {
NSLog(@"%@", snapshot.value[@"date_of_birth"]);
NSLog(@"%@", snapshot.value[@"full_name"]);
}];
I want the app to check if the name of the table is info and if so load the date of birth and full name. How can i do this?
Upvotes: 1
Views: 81
Reputation: 13546
You are observing changes to changes in database, instead of fetching records. Moreover, you haven't defined reference url users
against which you want to fetch data. Try this:
Firebase *ref = [[Firebase alloc] initWithUrl: @"https://sizzling-inferno-255.firebaseio.com/"];
//Refer to users entity
Firebase *usersRef = [ref childByAppendingPath: @"users"];
// Read data and react to changes
[usersRef observeEventType:FEventTypeValue withBlock:^(FDataSnapshot *snapshot) {
NSLog(@"%@ -> %@", snapshot.key, snapshot.value);
}];
Hope it helps!
Upvotes: 0
Reputation: 1412
You need to also add [ref child:@"users/info"]
just before observeEventType
child because you are just accessing the child one step below the root which is just "users" you aren't actually getting down to date of birth and full name.
Upvotes: 0
Reputation: 2683
The root object of your data is users
. You have to iterate through the data to get to info. Use can code something like below.
NSDictionary *info = snapshot.value[@"info"];
NSString *dob = info[@"date_of_birth"];
Upvotes: 1