This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
Hi all,
I'm struggling with a simple task of saving my database data into a local variable. I've followed a previous project that did the exact same thing, but with my new project I can't seem to figure it out?
private var breweries: [Brewery] = []
func loadDB(){
db.collection("breweries").document("gq1amvMbkE6AlEHR4CxK")
.addSnapshotListener { [self] (documentSnapshot, error) in
guard let document = documentSnapshot else {
print("Error fetching document: \(error!)")
return
}
guard let data = document.data() else {
print("Document data was empty.")
return
}
for (key, value) in data{
//Unwrap data here
//...
//Save data to local variable
self.breweries.append(newBrewery)
}
//Up until this point, data is saved to self.breweries
}
}
override func viewDidLoad() {
//Do delegate stuff
loadDB()
//Here, self.breweries is empty.
}
I don't quite understand what's wrong here. In my other project (from a course), the same idea is applied where you append a new Object to a local variable. For some reason here it won't work?
Hoping someone can give me some insight on what I'm doing wrong, or what best practices would be in this scenario.
Thank you!
Post Details
- Posted
- 2 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/swift/comme...