为什么 NSString 在 FireBase 查询块中为空?

Why is this NSString null in a FireBase query block?

我不明白为什么这个字符串在 FQuery 块中为空。当我在用户密钥处构建 dailyLog MutableDictionary 时,我的应用程序一直崩溃;

NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"MMMM dd, YYYY"];

NSString *userID = [[self.userProfile objectForKey:@"userID"] copy];
self.logFirebase = [[Firebase alloc] initWithUrl:@"https://urlName.firebaseio.com/DailyLog"];
[[[self.logFirebase queryOrderedByPriority] queryEqualToValue:userID childKey:@"userID"] observeEventType:FEventTypeValue withBlock:^(FDataSnapshot *snapshot) {

    if (![snapshot.value isEqual:[NSNull null]]) {
        NSMutableArray *data = [CGCFirebaseDataExtractor extractKeysAndObjects:snapshot.value];

        self.dailyLog = [data filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"Name CONTAINS[cd] %@",[df stringFromDate:[NSDate date]]]].lastObject;
    }else{
        self.dailyLog = [[NSMutableDictionary alloc] init];
        NSLog(@"users Profile:%@",self.userProfile);
        NSLog(@"users ID :%@",[self.userProfile objectForKey:@"userID"]);

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


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

    }

}];

编辑: 当我登录 self.userProfile 时,我得到了我想要的正确信息。但是当我从 FQuery 块中记录 userID 本身时,它是 null

这是我更新的崩溃数据:

2015-05-08 13:21:22.709 <appname>[4160:1321097] users Profile:{
"-JoirTqCXFFDY1psLTNn" =     {
    dateRegistered = "1431010405.81792";
    userID = "304D92EF-CE77-4A10-A55F-9847153699F7";
    userName = "User's Name";
};
 }
 2015-05-08 13:21:22.709 <appname>[4160:1321097] users ID :(null)
 2015-05-08 13:21:22.714 <appname>[4160:1321097] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** setObjectForKey: object cannot be nil (key: user)'
  *** First throw call stack:
  (0x1852082d8 0x196a340e4 0x1850f1428 0x10007de00 0x1001454d0 0x100390fd4 0x100390f94 0x100395c28 0x1851bf7f8 0x1851bd8a0 0x1850e92d4 0x18e8ff6fc 0x189caefac 0x10007f14c 0x1970b2a08)
   libc++abi.dylib: terminating with uncaught exception of type NSException

对不起,我是个白痴,没仔细看你的日志

2015-05-08 13:21:22.709 <appname>[4160:1321097] users Profile:{
"-JoirTqCXFFDY1psLTNn" =     {
    dateRegistered = "1431010405.81792";
    userID = "304D92EF-CE77-4A10-A55F-9847153699F7";
    userName = "User's Name";
};

这个对象显然是字典中的字典。第一个(外部)字典有键 "-JoirTqCXFFDY1psLTNn" ,这是它唯一的键 。这就是为什么尝试获取密钥 userID 失败的原因;该键是第二个(内部)字典的一部分。