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