swift - 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)
}
}
}
解决方案
推荐阅读
- javascript - 无法访问 JSON 对象中的属性
- algorithm - 使用排列和组合遍历 N*N 矩阵的方法数
- c# - 通过c#向外部网站提交登录表单时出错
- gradle - 颤振运行失败:配置项目“:shared_preferences”时出现问题
- php - IN FLEX SLIDER prevoius 和下一个按钮删除浏览器后退图标单击滑块上一张幻灯片幻灯片
- javascript - 如何在本地运行平均堆栈应用程序时获取包含在 angularjs 控制器中的 json 文件?
- reactjs - Pass props through Route with HOC
- xamarin - Xamarin - 再次询问设备位置
- c++ - 如果派生类还具有基类中不存在的虚函数,则创建的 vptr 数
- c++ - 在文件中找到字符串后替换它旁边的字符