How do I check if a firebase database value exists?

后端 未结 6 871
野趣味
野趣味 2020-11-28 05:36

I\'m using the Realtime Database with Google\'s Firebase, and I\'m trying to check if a child exists.

My database is structured as the following

- /          


        
6条回答
  •  被撕碎了的回忆
    2020-11-28 06:23

    You can check snapshot.exists value.

    NSString *roomId = @"room1";
    FIRDatabaseReference *refUniqRoom = [[[[FIRDatabase database] reference]
                                          child:@"rooms"]
                                         child:roomId];
    
    [refUniqRoom observeSingleEventOfType:FIRDataEventTypeValue
                                withBlock:^(FIRDataSnapshot * _Nonnull snapshot) {
    
        bool isExists = snapshot.exists;
        NSLog(@"%d", isExists);
    }];
    

提交回复
热议问题