I am trying to create a DataAccess layer for handling data access with firebase. Inside the closure, I can see data variable get 3 items, but once it gets out of the closure and go to return statement, it becomes nil!
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)
}
}
and her is my call
DataAccess.GetGames { (items) in
self.games = items
}