模糊使用下标(Swift 3) [英] Ambiguous Use of Subscript (Swift 3)
问题描述
我在下面的代码中使用下面的代码不正确地用于这个Firebase数据拉,但是我无法弄明白我做错了什么。我得到一个错误的使用下标的 let uniqueID = each.value [唯一ID事件号]为! Int
行。
I am using the subscript in the following code incorrectly for this Firebase data pull, but I can't figure out what I am doing wrong. I get an error of Ambiguous use of subscript for the let uniqueID = each.value["Unique ID Event Number"] as! Int
line.
// 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")
}
}
})
}
我试图应用我从这个<一个href =http://stackoverflow.com/questions/33642059/ambiguous-use-of-subscript-in-swift> post ,但是我无法弄清楚我失踪了,因为我以为我让编译器知道什么类型的字典与as? [String:AnyObject]
I tried to applying what I learned from this post, but I couldn't figure out what I am missing because I thought I was letting the compiler know what type of dictionary it is with the "as? [String:AnyObject]"
非常感谢任何想法或想法!
Any thoughts or ideas would be greatly appreciated!
推荐答案
我最喜欢处理数据的方法是尽可能地打开 FIRDataSnapshot
。
ref!.observe(.value, with: { (snapshot) in
for child in snapshot.children {
let msg = child as! FIRDataSnapshot
print("\(msg.key): \(msg.value!)")
let val = msg.value! as! [String:Any]
print("\(val["name"]!): \(val["message"]!)")
}
})
这篇关于模糊使用下标(Swift 3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!