The error is below,
Publishing changes from background threads is not allowed; make sure to publish values from the main thread (via operators like receive(on:)) on model updates.
How can I add this function to the task and return the task.?
func fetchAdPosts() async {
Task {
do{
let db = Firestore.firestore().collection("Ads")
let ads = try await db.getDocuments()
//error in the below code lines
self.ads = ads.documents.compactMap({ ad in
return try? ad.data(as: AdPost.self)
})
}
catch{
self.alertMessage = error.localizedDescription
showAlert.toggle()
}
}
}