didSet not called

Hi,

when using the new Combine api
Code Block
public func assign(to published: Published<Self.Output>.Publisher) where Self.Failure == Never
on a @Published property, didSet is not called when the value changes. Is that expected behavior or a bug?

Greetings,
Johannes
Property observers might not work the way you think they should when you have property wrappers. If you have a published property defined as:
Code Block swift
@Published
var myProperty: String


The type of that property is not String, it's Published<Self.Output>.Publisher (or something like that) - when you do something like myProperty = "A new value", the property wrapper is effectively intercepting the variable assignment, and updating its' internal representation. In other words, the value of _myProperty.projectedValue changes, but the value of myProperty does not - hence, your didSet observer is never called.

I'd call this expected behavior, but perhaps surprising if you're not familiar with how property wrappers work. You can, of course, subscribe to the publisher (which will give you willSet semantics), or you may be able to create an extension of Published to give you what you want

As far as I understand property wrappers, the type of myProperty *is* String, and the type of *_myProperty* is Published<String>.Publisher. And since myProperty is changed, it should call didSet.
didSet not called
 
 
Q