0

I asked a question yesterday that was marked as a duplicate, and when I updated the question it was not unmarked. So I am asking again here (as per stackoverflow's recommendation).

I am trying to sort by multiple values in firebase. I understand that is not possible, but i was given an example in another language which is only half helpful as how to go about doing it the right way. In any case i tried to follow the example given here Query based on multiple where clauses in firebase .

This is the structure of my firebase

room
  -KJe22sduQMz1DIs_DH6
      allowedParticipants: 
        14
     createdBy: 
       "Mr Tester"
     members: 
        "nmeMYnnSatRch5qKPJKIe7jEOLy2"
    participating: 
       true
    status: 
       "seedling"
    theme: 
       "Cats"
    totalNumberOfMembers: 
       1

and this is the code that I am trying to get to work

ref.queryOrderedByChild("status").queryStartingAtValue("active").queryEndingAtValue("active").observeEventType(.Value) { (snapshot: FIRDataSnapshot) in

    let themeOfEvent = snapshot.value

    if themeOfEvent?.value == pickedTheme {

        print("foo")

    }
}

Could somebody please post a useful comment or answer to help me? Thank you

Community
  • 1
  • 1
RubberDucky4444
  • 2,330
  • 5
  • 38
  • 70

1 Answers1

0

I was able to get help

This works

func listOfPossibleCompetitionsFromFirebase(){

    let createdRoomRef = firebase.child("room")
    createdRoomRef.queryOrderedByChild("status").queryStartingAtValue("active").queryEndingAtValue("active").observeEventType(.Value) { (snapshot: FIRDataSnapshot) in

        var themeCount = 0

        self.listOfOpenComps.removeAll()
        if let tmp = snapshot.value as? [String:AnyObject] {
            let keys = tmp.keys

            for key in keys {

                if let roomDetails = (tmp[key] as? [String:AnyObject]) {

                if let themeOfEvent = roomDetails["theme"] as? String where themeOfEvent == pickedTheme {
                    themeCount += 1
                    self.listOfOpenComps.append(key)
                }

                }
            }
        }

        dispatch_async(dispatch_get_main_queue(), { 
            self.tableView.reloadData()
        })

        print("rooms count: \(themeCount)")



    }




}
RubberDucky4444
  • 2,330
  • 5
  • 38
  • 70