Created
February 26, 2022 22:36
-
-
Save mitnick78/cfcd4eac8193c1a202f6faa8030d40fa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LearnViewModel: ObservableObject { | |
@Published var count = 0 | |
@Published var learns: [Learn] = [] | |
@Published var word: String = "" | |
@Published var word2: String = "" | |
@Published var note: String = "" | |
let manager = FirebaseManager.shared | |
init() { | |
getLearns() | |
} | |
func getLearns() { | |
manager.getLearnByUser().addSnapshotListener(resultLearn) | |
} | |
func resultLearn(query: QuerySnapshot?, error: Error?) { | |
DispatchQueue.main.async { | |
if let err = error { | |
print(err.localizedDescription) | |
} | |
if let all = query?.documents { | |
all.forEach { snapshot in | |
print("test") | |
print(snapshot.data()) | |
print("test") | |
let newLearn = Learn(dict: snapshot.data()) | |
self.learns.append(newLearn) | |
} | |
self.count += 1 | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment