Firebase with Swift ambiguous use of observeEventType

后端 未结 2 1052
日久生厌
日久生厌 2021-01-06 03:39

I\'ve been pulling my hair out because of this. Going to all the pages with related incidents and multiple tutorials I find nothing wrong with my code here, but somehow it o

相关标签:
2条回答
  • 2021-01-06 04:16

    Just some coding errors

    Remove: (snapshot)-> Void

    Change: child in snapshot as snapshot is not a sequence, whereas snapshot.children is

    I assume you want to store the friends name as a string and name is a key in your structure. So change self.friendsList.append(child.value) to

    let name = child.value["name"] as? String
    friendsList.append(name!)
    

    Here's the corrected code:

    var friendsList = [String]()
    
    ref.observeSingleEventOfType(.Value, withBlock: { snapshot in
    
        if snapshot.value is NSNull {
    
        } else {
            for child in snapshot.children {
                let name = child.value["name"] as? String
                friendsList.append(name!)
            }
            print("\(friendsList)")
        }
    })
    
    0 讨论(0)
  • 2021-01-06 04:16
    ref.observeSingleEvent(of: .value, with: { (snapshot) -> Void in
    
        })
    

    Work for me, Xcode 8.3.2

    0 讨论(0)
提交回复
热议问题