private func loadUserLearntChants() {
Task {
do {
try await profileViewModel.loadCurrentUser()
if let userId = profileViewModel.user?.userId {
let user = try await userManager.getUser(userId: userId)
if let learntChants = user.learntChants {
learntChantIds = learntChants
}
print(user)
}
} catch {
print("Error: \(error)")
}
}
}
When I print user it says learntChants is nil
Array of Objects (learntChants) is returning nil:

Screenshot from Firestore showing that learnt_chants isn't empty:

I read Unpacking Firestore array with objects to a model in swift, which said that you need to cast it to key-value type (Dictionary) first, then map it to LearntChant object
I tried this but it still didn't return anything
private func loadUserLearntChants() {
Task {
do {
try await profileViewModel.loadCurrentUser()
if let userId = profileViewModel.user?.userId {
let user = try await userManager.getUser(userId: userId)
if let learntChants = user.learntChants as? [[String: Any]] {
let learntChantObjects = learntChants.map { learntChant in
let chant = LearntChant(chantId: learntChants["chantId"] as? String ?? "none", voteType: learntChants["voteType"] as? String ?? "none")
return chant
}
}
}
} catch {
print("Error: \(error)")
}
}
}
learntChantObjects? In other words, the.mapmaps and creates a bunch of objects, and then adds them tolet learntChantObjectsbut then `learntChantObjects' silently goes out of scope.