0
我使用firebase執行查詢以檢查是否有任何具有特定值的子對象的對象。問題是如果沒有這樣的對象代碼不運行。因此,在下面的代碼中,如果沒有包含facebookID
的子項的對象是17
,則其餘代碼將永遠不會運行。有沒有辦法確定查詢何時發現0
結果?查詢爲空時的Firebase
func previousUser(completion:(result:Bool)->Void){
var queryFound = false
print("check if user is previous")
print(UserData.globalfacebookID)
let ref = Firebase(url:"https://amber-torch-556.firebaseio.com/Users")
ref.queryOrderedByChild("facebookID").queryEqualToValue(17).observeSingleEventOfType(.ChildAdded, withBlock: { snapshot in
print(snapshot.childrenCount)
print("query has ran")
UserData.globalparseID = snapshot.key
queryFound = true
completion(result:queryFound)
})