ios - 为什么这个 NSString 在 FireBase 查询 block 中为空?
<p><p>我不明白为什么这个字符串在 FQueryblock 中为空。当我在用户键上构建 dailyLog MutableDictionary 时,我的应用程序不断崩溃;</p>
<pre><code>NSDateFormatter *df = [ init];
;
NSString *userID = [ copy];
self.logFirebase = [ initWithUrl:@"https://urlName.firebaseio.com/DailyLog"];
[[ queryEqualToValue:userID childKey:@"userID"] observeEventType:FEventTypeValue withBlock:^(FDataSnapshot *snapshot) {
if (!]) {
NSMutableArray *data = ;
self.dailyLog = %@",]]].lastObject;
}else{
self.dailyLog = [ init];
NSLog(@"users Profile:%@",self.userProfile);
NSLog(@"users ID :%@",);
] forKey:@"date"];
forKey:@"user"];
forKey:@"calories"];
[ setValue:self.userProfile];
}
}];
</code></pre>
<p>编辑:
当我登录 self.userProfile 时,我得到了我想要的正确信息。但是当我从 FQueryblock 中记录用户 ID 本身时,它是空的</p>
<p>这是我更新的崩溃数据:</p>
<pre><code>2015-05-08 13:21:22.709 <appname> users Profile:{
"-JoirTqCXFFDY1psLTNn" = {
dateRegistered = "1431010405.81792";
userID = "304D92EF-CE77-4A10-A55F-9847153699F7";
userName = "User's Name";
};
}
2015-05-08 13:21:22.709 <appname> users ID :(null)
2015-05-08 13:21:22.714 <appname> *** 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
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>对不起,我是个白痴,没有仔细看你的日志。</p>
<pre><code>2015-05-08 13:21:22.709 <appname> users Profile:{
"-JoirTqCXFFDY1psLTNn" = {
dateRegistered = "1431010405.81792";
userID = "304D92EF-CE77-4A10-A55F-9847153699F7";
userName = "User's Name";
};
</code></pre>
<p>这个对象显然是字典中的字典。第一个(外部)字典有键 <code>"-JoirTqCXFFDY1psLTNn"</code> <em>这是它唯一的键</em>。这就是为什么尝试获取 key<code>userID</code> 失败的原因;该键是第二个(内部)字典的一部分。</p></p>
<p style="font-size: 20px;">关于ios - 为什么这个 NSString 在 FireBase 查询 block 中为空?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/30129116/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/30129116/
</a>
</p>
页:
[1]