willSet broken for array properties in Xcode 11.4

If you add the @Published to an array property, the willSet no longer fires. Remove the @Published and it works again.

This worked in XCode 11.3.1. Can someone confirm the same behaviour? Is this not going to be supported in future versions?


Test class

public class FooWillSet

{

@Published var keys = ["front", "back"]

{

willSet

{

print("new values\(newValue)")

print("old keys \(keys)")

}

}

}


func TestArray()

{

var foo = FooWillSet()

foo.keys.append( "garage" )

foo.keys.append( "condo" )

}

Replies

Yes, I confirm. Works in 11.3, not in 11.4 (in playground).

Same with didSet.


Should file a bug.

The problem comes from append.


I did the following test in playground, XCode 11.4, OSX 10.15.4


public class FooWillSet
{
    @Published var keys = ["front", "back"]
    {
        willSet
        {
            print("new values\(newValue)")
            print("old keys \(keys)")
        }
    }
}

func TestArray()
    {
        var foo = FooWillSet()
        foo.keys.append( "garage" )
        foo.keys.append( "condo" )
        print("Called TestArray")
    }
TestArray()


I get only

Called TestArray



Now, I add 2 new lines 18 and 19:


public class FooWillSet
{
    @Published var keys = ["front", "back"]
    {
        willSet
        {
            print("new values\(newValue)")
            print("old keys \(keys)")
        }
    }
}

func TestArray()
    {
        var foo = FooWillSet()
        foo.keys.append( "garage" )
        foo.keys.append( "condo" )
        foo.keys = foo.keys + ["garage New"]
        foo.keys = foo.keys + ["condo"]
        print("Called TestArray")
    }
TestArray()


I get:

new values["front", "back", "garage", "condo", "garage New"]

old keys ["front", "back", "garage", "condo"]

new values["front", "back", "garage", "condo", "garage New", "condo"]

old keys ["front", "back", "garage", "condo", "garage New"]

Called TestArray


Which shows the problem is that append is not triggering the observer (just as if it was working on a local copy ?)

But adding directly and item does trigger the observer.


Hope that will help focus bug search (did you file a bug report ?).

I'll report a bug on my side.


BUG REPORT : FB7642371