I have this code in an MVVM
code in SwiftUI. My Objective is when the app loads for the first time to return the result without the filter. When I press the button on the view to trigger CatLotViewModel
to reload the filtered data but can't seem to figure out I can trigger it.
class CatLotViewModel: ObservableObject {
//MARK: - Properties
@Published var catViewModel = [CatViewModel]()
private var cancellabels = Set<AnyCancellable>()
init() {
MyAPIManager().$cat.map{ kitten in
// Filter
let filtered = kitten.filter{ ($0.meals.contains(where: {$0.feed == false}))}
return filtered.map { park in
MyCatViewModel(parking: park)
}
// return kitten.map { park in
// CatViewModel(parking: park)
// }
}
.assign(to: \.catViewModel, on: self)
.store(in: &cancellabels)
}
}