简体   繁体   English

如何在Swift中将Firebase数据库快照转换为数组列表?

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

I am making an app using Swift and Firebase. 我正在使用Swift和Firebase制作应用程序。 I want to get an array list containing all of the numbers under a certain user id (images attached below). 我想获得一个数组列表,其中包含某个用户ID下的所有数字(下面附有图像)。 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"). 我的意思是,我希望能够调用一个函数,该函数返回一个数组列表,其中包含作为用户ID的子代放置的每个整数(从低到高),但不包含其值(在这种情况下为“ 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: 该函数打印: 在此处输入图片说明

This is an image of the realtime database: 这是实时数据库的图像: 在此处输入图片说明

从键创建数组

let array = Array(dictionary.keys)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM