As the title suggests, I have a class marked with @Observable. Within the class I have multiple var's. When one of my var's changes (formation), I want to run an updateOrCreateContent(). I had thought I could just do this with a bit of combine, but I'm struggling to get it working...
The code below has a compile error at $formation
When I mark formation @Published, it generates a different compile error: "Invalid redeclaration of synthesized property '_formation'"
any help appreciated thanks
class LayoutModel {
var players: [Player] = []
var formation: Formation = .f433
var cancellables = Set<AnyCancellable>()
init(players: [Player], formation: Formation) {
self.players = players
self.formation = formation
updateOrCreateContent()
$formation.sink(receiveValue: { _ in
self.updateOrCreateContent()
})
.store(in: &cancellables)
}