2016-05-24 31 views
0

我想知道是否有任何方式與迅速和firebase,從同一個孩子得到多個數字?並平均所有數字。Firebase獲取多個結果

示例, 每個授權用戶都將數字保存到數據庫。然後,當他們查看保存的部分中的數字時,它將平均所有其他用戶的數字,並將其與這些數字進行比較。

我可以得到所有的數據保存,我可以得到的數據發回的信息,但只是將其從名單

我已經嘗試了不同的方式將一個號碼,但我不能去工作。任何幫助都是極好的。

我會張貼一些代碼,但它都沒有事先

回答

0

再次合作真正的好

感謝您的例子,你可以使用childByAutoID創建用戶隨機唯一標識符。爲了從一個孩子獲得多個值,您可以在設置孩子值時使用逗號。像這樣,

struct getInput { 
    var inputType: String! 
    } 
    //copying and pasting this code into your code will not work, however 
    //you should be able to understand why and how this works. 

    let getUsername = getInput(inputType: usernameTextField.text!) 
    let getPassword = getInput(inputType: passwordTextField.text!) 

    let userReference = database.reference().child("users") 
    userReference.setValue(getUsername.inputType) 
    let childByAutoID = userReference.childByAutoId() 
    childByAutoID.setValue(["username": getUsername.inputType, "password": getPassword.inputType])