Hi i'm building my app with Firebase and Swift3 , but i get this error when i run the code "(child:) Must be a non-empty string and not contain '.' '#' '$' '[' or ']''" . This is the func where i get the error, even if everything should work
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
print (self.otherUserUid)
let reference = Database.database().reference().child("User-messages").child(Auth.auth().currentUser!.uid).child(self.otherUserUid).queryLimited(toLast: 51)
reference.observeSingleEvent(of: .value, with: {[weak self] (snapshot) in
print("IN")
let messages = Array(JSON(snapshot.value as Any).dictionaryValue.values).sorted(by: { (lhs, rhs) -> Bool in
return lhs["date"].doubleValue < rhs["date"].doubleValue
})
let converted = self!.convertToChatItemProtocol(messages: messages)
if converted.isEmpty == true {
print ("empty")
}
let navcontroller = segue.destination as! UINavigationController
let chatlog = navcontroller.topViewController as! ChatLogController
chatlog.userUID = self.otherUserUid
chatlog.dataSource = DataSource(initialMessages: converted ,uid: (self?.UIDLabel.text)!)
chatlog.MessagesArray = FUIArray(query: Database.database().reference().child("User-messages").child(Me.uid).child((self?.UIDLabel.text)!).queryStarting(atValue: nil, childKey: converted.last?.uid), delegate: nil)
messages.filter({ (message) -> Bool in
return message["type"].stringValue == PhotoModel.chatItemType
}).forEach({ (message) in
self?.parseURLs(UID_URL: (key: message["uid"].stringValue, value: message["image"].stringValue))
})
})
}
The app crashes before printing "IN", but when i print self.otherUserUid it returns the right value. I also updated the pods but it didn't solved anything. Thanks in advance :)
SOLUTION : The mistake is that i inserted a func in the viewDidLoad of the ChatLogController, where when an user decides to end the chat the other one gets informated, but that func needs the other user Uid and when the view is loading there isn't any uid because it has to be passed, so i inserted the func inside "viewDidAppear" and everything works fine. Thanks to everyone that tried to help me.