Faizul Karim
Faizul Karim

Reputation: 146

Firebase query in iOS swift

This is my first screenshot database in firebase:

This is my first screenshot database model

This is my second screenshot database in firebase:

enter image description here

I am able to retrieve data from firebase also set in table view. But I want all data that which first screenshot database key (1album) equal to second database post_key: 1album.

I tried like this:

refhandel = ref.child("SongPlay").child("1album"] ).queryOrdered(byChild:"post_key").observe(.childAdded, with: { (snapshot) in

if let item = snapshot.value as? [String: AnyObject]{

            let music = MusicDataModel()
            music.setValuesForKeys(item)
            MusicData.append(music)
   }
})

Upvotes: 2

Views: 1380

Answers (1)

Faizul Karim
Faizul Karim

Reputation: 146

after read firebase documentation, I got my Answer where i made mistake. here what i was done. i just replace queryEqual instance of child

refhandel = ref.child("SongPlay").queryOrdered(byChild:"post_key").queryEqual(toValue: post_key[myIndex]).observe(.childAdded,   with: { (snapshot) in

if let item = snapshot.value as? [String: AnyObject]{

        let music = MusicDataModel()
        music.setValuesForKeys(item)
        MusicData.append(music)
  }

 })

Upvotes: 2

Related Questions