Upvote:20

Aprove answer
func body(content: Content) -> some View {
    content
        .onAppear()   // <--- this makes it work
        .onReceive(viewModel.$myProperty) { theValue in
            print("-----> The Value is \(theValue)") // <--- this will be executed
    }
}

Upvote:2

.onChange(of: viewModel.myProperty) { newValue in
        print("newValue \(newValue)")
    }

Credit Goes to: stackoverflow.com

Related question with same questions but different answers