Ios FireBase-将用户添加到用户列表

Ios FireBase-将用户添加到用户列表,ios,objective-c,firebase,Ios,Objective C,Firebase,嗨,我正在尝试学习firebase,因为Parse将关闭,我在向数据库添加用户时遇到了一些问题 在网站上的iOS教程之后,我首先使用以下命令收听用户列表: - (void)setUpRootReference { self.rootReference = [[Firebase alloc] initWithUrl:@"firebaseurl"]; // Attach a block to read the data at our posts reference [self.rootReferen

嗨,我正在尝试学习firebase,因为Parse将关闭,我在向数据库添加用户时遇到了一些问题

在网站上的iOS教程之后,我首先使用以下命令收听用户列表:

- (void)setUpRootReference {
self.rootReference = [[Firebase alloc] initWithUrl:@"firebaseurl"];
// Attach a block to read the data at our posts reference
[self.rootReference observeEventType:FEventTypeValue withBlock:^(FDataSnapshot *snapshot) {
    NSLog(@"%@", snapshot.value);
    if (snapshot.value != [NSNull null]) {
        userDic = [snapshot.value objectForKey:@"users"];
        NSLog(@"user dictionary: %@", userDic);
    }
} withCancelBlock:^(NSError *error) {
    NSLog(@"%@", error.description);
}];
}    
然后,在用户使用Instagram成功登录后,我想将新用户附加到现有用户列表中。但现在它只是被写得太多了,我总是只剩下一个用户

以下是用户注册后我的完成代码:

//create a path on firebase for users
        Firebase *usersRef = [self.rootReference childByAppendingPath: @"users"];

        [userDic setValue:newUserDic forKey:newUser.instagramHandle];
        [usersRef setValue:userDic];
有人知道我如何在现有的用户字典中添加一个值,而不是每次删除并创建一个新的值吗

谢谢

更新:

我找到了让它工作的方法。每次创建新用户时,您都希望对该用户进行新引用

解决方案:

//create a path on firebase for users
        Firebase *allUsersRef = [self.rootReference childByAppendingPath: @"users"];
        Firebase *newUserRef = [allUsersRef childByAppendingPath:newUser.instagramHandle];
        [newUserRef setValue:newUserDic];
现在将添加一个新的用户词典,关键是用户instagram句柄

NSDictionary *nickname = @{
    @"nickname": @"Igor Kuznetsov",
};
[userRef updateChildValues: nickname];
有一个名为updateChildValues的方法。试试这样的。 [userRef UpdateChildValue:昵称];
我上面的示例将更改例如用户的昵称,在您的情况下,您可以更改您感兴趣的属性的昵称。

Idk about firebase但要修改现有词典,您必须使用
NSMutableDictionary
而不是
NSDictionary
。这在,它确实使用了
childByAppendingPath
。整个iOS指南非常值得一读。另请参阅昨天的这个密切相关的问题: