Firebase Swift: queryEqualToValue by childKey is not working

后端 未结 2 875
无人及你
无人及你 2020-12-30 07:46

Has anyone have any luck using the function:

.queryEqualToValue(value: AnyObject?, childKey: String?)

Two things:

1) The childKey

2条回答
  •  被撕碎了的回忆
    2020-12-30 08:05

    The following is written in the Firebase documentation:

    queryEqualToValue Return items equal to the specified key, value, or priority, depending on the order-by method chosen.

    Retrieve Data on iOS

    The important part is: "depending on the order-by method chosen."

    So make sure, you combine the queryEqualToValue-Method with a orderBy-Method.

    For example:

        let groupState = "open"
    
        ref.child("groups").queryOrdered(byChild:"state").queryEqual(toValue:groupState).observe(enventType: .value, with: { snapshot in
            // Returns all groups with state "open"
            for group in snapshot.children {
                print(group)
            }
        })
    

    PS: The variant with childKey is not mentioned in the new Firebase iOS-Guides.

提交回复
热议问题