我正在尝试创建一个DataAccess层来处理使用firebase的数据访问。在闭包内部,我可以看到数据变量得到3个项目,但是一旦它离开闭包并转到return语句,它就变为零了!
static let ref = Database.database()
static func GetGames(completion : @escaping ([String]) ->()){
ref.reference(withPath: "games").observe(.value, with: { (snapshot) in
guard let data = snapshot.value as? [String] else { return }
completion(data)
})
{ (error) in
print("failed to fitch data",error)
}
}
她是我的电话
DataAccess.GetGames { (items) in
self.games = items
}