2017-02-13 21 views
0

我正在關注新的Firebase文檔以執行寫入操作。但是,我沒有看到任何代碼可以讓我聽取Firebase對寫操作的迴應。Firebase寫操作的Swift響應處理程序

這裏是我的代碼:

ref.child("Canciones").childByAutoId().setValue(["Categoria":song.categoria, "Titulo":song.titulo, "Autor":song.autor, "Votos":song.votos]) 

我在尋找的東西會返回響應,我來通知已成功執行請求的用戶。例如:

ref.child("Canciones").childByAutoId().setValue(["Categoria":song.categoria, "Titulo":song.titulo, "Autor":song.autor, "Votos":song.votos]) { response in 
if error != nil { 
//..etc..// 
} 

謝謝!

回答

2
let message = ["name": "puf", "text": "Hello from iOS"] 
ref!.childByAutoId().setValue(message) { (error) in 
    print("Error while writing message \(error)") 
} 
0

documentation和作爲替代答案

func setValue(_ value: Any?, withCompletionBlock block: @escaping (Error?, FIRDatabaseReference) -> Void) 

和這樣

let ref = rootRef.child("Canciones").childByAutoId()  
ref.setValue("Hello, World", withCompletionBlock: { (error, ref) in 
     if error == nil { 
      print("success") 
     } else { 
      print("failure") 
     } 
    }) 
使用
相關問題