vendredi 8 mai 2015

Why is this NSString null in a FireBase query block?

I can't figure out why this string is null inside the FQuery block. My app keeps crashing when I build the dailyLog MutableDictionary at the user key;

NSString *userID = [self.userProfile objectForKey:@"userID"];
self.logFirebase = [[Firebase alloc] initWithUrl:@"http://ift.tt/1zK8jF4"];
[[[self.logFirebase queryOrderedByChild:@"userID"] queryEqualToValue:userID] observeEventType:FEventTypeValue withBlock:^(FDataSnapshot *snapshot) {

    FQuery *queryRef = [[self.logFirebase queryOrderedByChild:@"date"] queryEqualToValue:[df stringFromDate:[NSDate date]]];
    [queryRef observeEventType:FEventTypeValue withBlock:^(FDataSnapshot *snapshot) {

        NSLog(@"value:%@", snapshot.value);
        if (![snapshot.value isEqual:[NSNull null]]) {
            self.dailyLog = snapshot.value;
        }else{
            self.dailyLog = [[NSMutableDictionary alloc] init];
            NSLog(@"users Profile:%@",self.userProfile); //This is working fine, I see data and I'm using the right keys

            [self.dailyLog setObject:[df stringFromDate:[NSDate date]] forKey:@"date"];
            [self.dailyLog setObject:userID forKey:@"user"];
            [self.dailyLog setObject:[NSNumber numberWithInt:450] forKey:@"calories"];


            [[self.logFirebase childByAutoId] setValue:self.userProfile];

        }

    }];

}];

EDIT: When I log self.userProfile, I get the proper info I want. But when I log the userID itself from within the FQuery block, it's null

Aucun commentaire:

Enregistrer un commentaire