1

I have an int userCoin that holds the user coin and I want to equal Firebase' value to my int value.

I have this code

    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);
}];

but it wont work. It says:

ViewController.m:45:18: Incompatible pointer to integer conversion assigning to 'int' from 'id _Nullable'

AL.
  • 36,815
  • 10
  • 142
  • 281
excitedmicrobe
  • 2,338
  • 1
  • 14
  • 30

1 Answers1

1

Firebase is giving you an NSNumber* and that isn't the same thing as an int. Call snapshot.value[@"Coin"].intValue to convert it to an int.

Collin Jackson
  • 110,240
  • 31
  • 221
  • 152