How can I convert a Firebase Database Snapshot into an Array List in Swift?

Bob Samuels

I am making an app using Swift and Firebase. I want to get an array list containing all of the numbers under a certain user id (images attached below). What I mean by this is I want to be able to call a function that returns an array list containing every integer (from low to high) placed as a child of the user id, but not containing their values (in this case "true"). I have already gotten a snapshot of the data (see code below), but I am unsure as to what to do now.

My Code:

func likeToLikeForAll() {

    let uid  = Auth.auth().currentUser?.uid
    Database.database().reference().child("Liked Movies").child(uid!).observeSingleEvent(of: .value, with: { (snapshot) in
        if let dictionary = snapshot.value as? [String: AnyObject] {
            print()
            print("SNAP:")
            print(snapshot.value!)
            print()
        }
    })
}

The function prints: enter image description here

This is an image of the realtime database: enter image description here

Joakim Danielson

Create an array from the keys

let array = Array(dictionary.keys)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Swift Firebase - Convert database snapshot into an array

How can I map my Firebase snapshot in Swift 4?

How can I convert an array to string in swift?

How can I convert this Firebase database to SQL database?

How can i get data snapshot and then update database in firebase cloud functions http request

How can I convert an Int array into a String? array in Swift

How can I put a list of snapShot of String in array inside the DropdownButton flutter

How to convert a NSUSerdefaults AnyObject? to SWIFT Array so that I can append to it?

How can I parse JSON to convert this to an array of objects in Swift?

How can I convert an array with custom classes to JSON in swift 3

How can I convert UIImage to Byte Array In Swift 4

How can i update an object (map) in an array with swift in firestore database?

How I can convert an array value from LInkedHashMap to the List?

How can I convert this list of pairs into an object that contains an array of arrays?

How can I convert a list of strings to an array of float numbers?

Flutter: Parsing Firebase Realtime Database snapshot to list

How to create an array in firebase database in iOS swift

How can i convert an array

Can i Convert this array to List or Set in Typescript?

How can I change an exist list, to a new list? || android - firebase realtime database

How can I convert an Image selected from my gallery or camera snapshot from my flutter app to base64, display it before I persist to database

How can i convert my firebase realtime database function to firestore function

How to read deeper into a snapshot Firebase Swift 3?

How to include firebase snapshot key value? [Swift]

How can I use Glide with Firebase Database?

How can I modify Firebase Database Rules

How can I nest data in Firebase Database?

How can I store object has a multiple strings from firebase database using swift3

How can I read the value of a Firebase database dictionnary created using .childByAutoId() in Swift?