I am trying to give the user the opportunity to save or unsave a news article. The Save button saves it on the backend but the image does not update when the backend updates.
@State var industryInsights = [IndustryInsight]()
List {
ForEach(industryInsights, id: \.self) { insight in
IndustryInsightRowView(insight: insight)
}
}
I am not sure the best way of doing this, but I would like the button image to update as the user presses the button. Any help would be appreciated.
InsightClass and properties
struct IndustryInsight: Codable, Hashable, Identifiable {
let id: Int
let industry, alert, date: String
let url: String
let status: String
}
Function when save button pressed.
func saverowButtonClicked(alert: IndustryInsight) {
if alert.status == "Saved" {
RestAPI.changeStatusIndustryAlerts(id: alert.id, status: "Unsave", completionHandler: { () in
})
} else {
RestAPI.changeStatusIndustryAlerts(id: alert.id, status: "Save", completionHandler: { () in
})
}
}