dbRef关闭被绕过

时间:2019-01-08 08:05:38

标签: swift

我正在迅速地火力发力。但是,当运行 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)
    }
   } 

}

0 个答案:

没有答案