Mohammed Fazil
Mohammed Fazil

Reputation: 31

How to Fetch Specific Datas From Firebase

[
  Beacons:[    
    Beacons1:[
        heritage:"Heritage Point1" 
        uuid:"qwerty"   
        ]   
    Beacons2:[
        heritage:"Heritage Point2"
        uuid:"asdfgh"
        ]
  ]

  Heritage Point1: [
          Title:"India"
          location:[
                lat:"11.345234"
                lon:"35.643521"
                ]
           Description:"Democratic Country"
  ]
]

This is the Firebase Model!!! I have uuid I need to fetch datas from specific heritage points1 from my Beacons Loop how its Possible.. I know only fetching single values. Here is My Code!!

   'let rootRef = Database.database().reference()

    rootRef.child("Beacons").observe(.childAdded, with: {snapshot in

    guard let dictionary = snapshot.value as? [String: AnyObject] else { return }

   let uuidDatas = dictionary["uuid"] as? String

   let heritageDatas = dictionary["heritage"] as? String

        print("uuidData: \(uuidDatas ?? "")")
        print("HeritageData: \(heritageDatas ?? "")")

  })'

Output

uuidData: Optional("qwerty")
HeritageData: Heritage Point1
uuidData: Optional("asdfgh")
HeritageData: Heritage Point2

Anyone Please to help me to get Heritage Point Datas I'm using swift 4 language

Upvotes: 0

Views: 67

Answers (1)

John Doe
John Doe

Reputation: 185

Please fix your question format first as it is really hard to read and understand what you are trying to do in your code.

If you want to get a specific item in the Firebase Database, this example might help you:

// somebody try this if we can have space in-between Heritage and point1
let myDatabaseRef = Database.database().reference(withPath: "Beacons/Heritage Point1")

myDatabaseRef.observe(.value) { (snap:DataSnapshot) in 

    // Do whatever you want with your snapshot here
    print(snap.value)
}

or follow along this tutorial from their official YouTube Page: https://www.youtube.com/watch?v=joVi3thZOqc&list=PLl-K7zZEsYLn-elkHPhDuuwdCZ93BXnrB&index=19

Upvotes: 1

Related Questions