Ambiguous Use of Subscript (Swift 3)

后端 未结 2 618
逝去的感伤
逝去的感伤 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: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"]!)")
        }
    })
    

提交回复
热议问题