下标的模糊使用(Swift 3)
发布时间:2020-12-14 05:46:31 所属栏目:百科 来源:网络整理
导读:我正在使用以下代码中的下标错误地获取此Firebase数据,但我无法弄清楚我做错了什么.我得到一个错误,即对于let uniqueID = each.value [“唯一ID事件编号”]的下标不明确使用!直线. // Log user inif let user = FIRAuth.auth()?.currentUser { let uid = us
我正在使用以下代码中的下标错误地获取此Firebase数据,但我无法弄清楚我做错了什么.我得到一个错误,即对于let uniqueID = each.value [“唯一ID事件编号”]的下标不明确使用!直线.
// 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?[String:AnyObject]” 任何想法或想法将不胜感激!
我处理数据的首选方法是尽可能晚地打开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"]!)") } }) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |