【问题标题】:Equal an int value from firebase realtime database?等于firebase实时数据库中的int值?
【发布时间】:2017-06-23 03:55:36
【问题描述】:

我有一个 int userCoin 持有用户硬币,我想将 Firebase 的值与我的 int 值相等。

我有这个代码

    self.databaseRef = [[FIRDatabase database] reference];
NSString *userID = [FIRAuth auth].currentUser.uid;
[[[_databaseRef child:@"users"] child:userID] observeSingleEventOfType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot * _Nonnull snapshot) {
    // Get user value
    NSLog(@"%@",snapshot.value[@"Profile Picture"]);
    userCOin = snapshot.value[@"Coin".init];


} withCancelBlock:^(NSError * _Nonnull error) {
    NSLog(@"%@", error.localizedDescription);
}];

但它不会工作。它说:

ViewController.m:45:18:指向从“id _Nullable”分配给“int”的整数转换的不兼容指针

【问题讨论】:

    标签: ios objective-c firebase firebase-database


    【解决方案1】:

    Firebase 为您提供 NSNumber*,这与 int 不同。调用snapshot.value[@"Coin"].intValue 将其转换为int

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-10-09
      • 2020-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多