使用唯一ID推入Firebase [英] Push into Firebase with unique ID
问题描述
我试图将数组存储到我的Firebase后端, :
Firebase * f = [[Firebase alloc] initWithUrl:@https://test.firebaseio.com/items ]。
[f setValue:@ {@UNIQUE OBJECT ID HERE:@ {@meh:@lol,@hum:@kek}}];
它按预期工作,但是我需要为每个对象设置一个唯一的ID。现在,每次运行该方法时,Firebase都会将新数据替换为旧数据。
从Web开发背景来看,我知道在JavaScript中我会这样做:
var ref = new Firebase(https://test.firebaseio.com/items);
ref.push({meh:lol,hum:kek)};
得到预期的结果,因为它提供了一个名称为-IuxeSuSiNy6xiahCXa0的对象。 / p>
如何在ObjC中完成此项工作?
在Objective-C中的系统中,但是语法却是一个不同的触摸。
Firebase * ref;
Firebase * autoId = [ref childByAutoId];
Firebase * f = [[Firebase alloc] initWithUrl:@https://test.firebaseio.com/items];
[f setValue:@ {@UNIQUE OBJECT ID HERE:@ {@meh:@lol,@hum:@kek}}];
应该是:
Firebase * f = [[Firebase alloc] initWithUrl:@https://test.firebaseio.com/items];
[[f childByAutoId] setValue:@ {@meh:@lol,@hum:@kek}}];
I'm building my first iOS app and I'm using Firebase as my backend.
I'm trying to store an array into my Firebase backend like so:
Firebase* f = [[Firebase alloc] initWithUrl:@"https://test.firebaseio.com/items"];
[f setValue:@{@"UNIQUE OBJECT ID HERE": @{@"meh": @"lol", @"hum": @"kek"}}];
It works as expected, but I need to have an unique id for each "object". Right now, every time that method runs Firebase just replaces the old data with the new one.
Coming from a web dev background, I know that in JavaScript I would do this:
var ref = new Firebase("https://test.firebaseio.com/items");
ref.push({meh: "lol", hum: "kek")};
Which yields the expected result, since it gives the object above a name of "-IuxeSuSiNy6xiahCXa0".
How do I accomplish this in ObjC?
Firebase has build in system in Objective-C as well, but the syntax is a touch different.
Firebase * ref;
Firebase * autoId = [ref childByAutoId];
This:
Firebase* f = [[Firebase alloc] initWithUrl:@"https://test.firebaseio.com/items"];
[f setValue:@{@"UNIQUE OBJECT ID HERE": @{@"meh": @"lol", @"hum": @"kek"}}];
Should be:
Firebase* f = [[Firebase alloc] initWithUrl:@"https://test.firebaseio.com/items"];
[[f childByAutoId] setValue:@{@"meh": @"lol", @"hum": @"kek"}}];
这篇关于使用唯一ID推入Firebase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!