【发布时间】:2016-12-05 18:35:15
【问题描述】:
我对 Firebase 还是很陌生,而且我可以看到他们的功能到目前为止我很喜欢它。我计划在未来继续使用它,但我想使用可能的最佳实践,所以我试图在 Firebase 中进行多位置更新, 我让它以两种方式工作,但我想确定哪一种是正确的、最好的方式,我想知道为什么。
第一种方式:
NSDictionary *childUpdates = @{
[[NSString stringWithFormat:@"/%@/",IDMAllIDMsPathFIR] stringByAppendingString:key]:idmData,
[NSString stringWithFormat:@"/%@/%@/%@/", IDMUserIDMsPathFIR,self.currentFirebaseUserId, key]: idmData
};
[self.databaseReference updateChildValues:childUpdates];
第二种方式是这样的:
FIRDatabaseReference * allIDMsRef = [[self.databaseReference child:IDMAllIDMsPathFIR] child:key];
FIRDatabaseReference * userIDMsRef = [[[self.databaseReference child:IDMUserIDMsPathFIR] child:self.currentFirebaseUserId] child:key];
[userIDMsRef updateChildValues:idmData];
[allIDMsRef updateChildValues:idmData];
self.databaseReference 是 Firebase 数据库的根引用
请让我知道哪个更好以及为什么更好,我非常感谢对此的任何想法。
【问题讨论】:
标签: ios objective-c firebase firebase-realtime-database