Consider the following code:
class ViewModel: ObservableObject {
@Published private(set) var value = 0
}
let vm = ViewModel()
// vm.value = 42 // <- This fails since value is private
Just(42).assign(to: vm.$value) // this compiles
print(vm.value) // and changes the private value
It is unexpected that you can use the assign(to:)
method on publisher to circumvent access modifiers on a class, allowing you to change private fields.
I understand why this is possible (due to how property wrappers work), but it is incredibly subtle and gives an escape hatch to break encapsulation of the class.