realtime configurar con agregar ios firebase swift3 firebase-database nsdictionary

ios - configurar - firebase realtime database



NSDictionary tiene valor de none (1)

Solucioné el problema simplemente dando el uid del otro usuario NSDictionary a una nueva variable que creé en viewdidLoad. De esta forma, no tengo problemas para desempaquetar las opciones más adelante.

Quiero que el usuario agregue Amigos. Sin embargo cada vez que hago clic en el botón addFriend , obtengo un punto de interrupción con un thread 1 . No hay más información de error en lugar de 11db . He descubierto que el NSDictionary de "otro usuario" tiene el valor de ninguno. Esa es la razón por la que todo no está funcionando. Sin embargo, no tengo idea de por qué es eso. Fuera de la misma NSDictionary , obtengo el nombre de usuario y el perfil Pic. ¿Por qué es nil entonces?

var otherUser: NSDictionary? override func viewDidLoad() { super.viewDidLoad() databaseRef.child("user").child(self.otherUser?["uid"] as! String).observe(.value, with: { (snapshot) in let uid = self.otherUser?["uid"] as! String self.otherUser = snapshot.value as? NSDictionary self.otherUser?.setValue(uid, forKey: "uid") }) { (error) in print(error.localizedDescription) } } @IBAction func addFriend(_ sender: Any) { if self.befreunden.titleLabel?.text == "Als Freund hinzufügen" { let friendRef = "befreundet//(self.loggedinUSerData?["uid"] as! String)//(self.otherUser?["uid"] as! String)" let BefreundenData = ["username":self.otherUser?["username"] as? String, "ProfilePic":self.otherUser?["urltoImage"] as! String!] let childUpdats = [friendRef:BefreundenData] databaseRef.updateChildValues(childUpdats) }else { FreundeAnzahl = self.otherUser?["AnzahlFreunde"] as! Int + 1 } }

Editar:

Acabo de descubrir que NSDictionary of otherUser tiene todos los valores necesarios dentro de viewdidLoad. Pero tan pronto como llamo al uid del otherUser en la función addFriend devuelve un valor de nil. ¿Por qué está sucediendo?