【发布时间】:2017-02-26 16:11:18
【问题描述】:
我在以下代码中错误地使用了此 Firebase 数据提取中的下标,但我不知道我做错了什么。我收到 let uniqueID = each.value["Unique ID Event Number"] as! Int 行的下标使用不明确的错误。
// Log user in
if let user = FIRAuth.auth()?.currentUser {
let uid = user.uid
// values for vars sevenDaysAgo and oneDayAgo set here
...
let historyRef = self.ref.child("historyForFeedbackLoop/\(uid)")
historyRef.queryOrdered(byChild: "Unix Date").queryStarting(atValue: sevenDaysAgo).queryEnding(atValue: oneDayAgo).observeSingleEvent(of: .value, with: { snapshot in
if (snapshot.value is NSNull) {
print("user data not found")
}
else {
if let snapDict = snapshot.value as? [String:AnyObject] {
for each in snapDict {
// Save the IDs to array.
let uniqueID = each.value["Unique ID Event Number"] as! Int
self.arrayOfUserSearchHistoryIDs.append(uniqueID)
}
}
else{
print("SnapDict is null")
}
}
})
}
我尝试应用从 post 中学到的知识,但我无法弄清楚我缺少什么,因为我认为我让编译器知道它是什么类型的字典与“as?[字符串:任何对象]"
任何想法或想法将不胜感激!
【问题讨论】:
标签: swift dictionary firebase firebase-realtime-database subscript