首页 > 解决方案 > dbRef 关闭被绕过

问题描述

我正在快速使用firebase。但是,当运行dbRef.child("json").observeSingleEvent(of: .value) 行时,不会执行其后面的闭包。它直接跳转到函数的末尾。

我的数据库确实有这样的层次结构。json/(radomID)/url:"字符串"

我可以知道我可以解决/调试问题吗?

import Foundation
import FirebaseStorage
import FirebaseDatabase
import FirebaseAuth

class SaveLoadService {

var delegate: gameRecordProtocol?

var gameRecordArray = [gameRecord]()



static func getPhotos(completion: @escaping (String) -> Void) -> Void {

    //Getting a reference to the database
    let dbRef = Database.database().reference()


    //Make the db call
    dbRef.child("json").observeSingleEvent(of: .value) { (snapshot) in


        var jsonUrl: String = ""

        //get the list of snapshot
        let snapshots = snapshot.children.allObjects as? [DataSnapshot]

        if let snapshots = snapshots {



            for snap in snapshots {

                print(snap)

            }

        }

        // after parsing the snapshots, call the completion closure
        completion(jsonUrl)
    }
   } 

}

标签: swift

解决方案


推荐阅读