Ambiguous Use of Subscript (Swift 3)

后端 未结 2 601
逝去的感伤
逝去的感伤 2020-12-12 06:11

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 su

相关标签:
2条回答
  • 2020-12-12 06:27

    Taking Frank's feedback into account, here is the actual working code I used that follows that approach in case it's helpful.

    // 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 {
    
                     for child in snapshot.children {
    
                        let data = child as! FIRDataSnapshot
                        let value = data.value! as! [String:Any]
                        self.arrayOfUserSearchHistoryIDs.append(value["Unique ID Event Number"] as! Int)
                     }
                }
       })
    }
    
    0 讨论(0)
  • 2020-12-12 06:29

    My preferred way of dealing with data is to unwrap the FIRDataSnapshot as late as possible.

    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"]!)")
        }
    })
    
    0 讨论(0)
提交回复
热议问题