willSet causing copy-on-write types to copy on mutations?

Is it correct that having a willSet on a property will cause copy-on-write types to always copy their internals when the property is mutated? I guess it would make sense because both the current value and the new value are available in the willSet. Using the @Published property wrapper seems to be causing this as well, I guess it uses a willSet internally. Is there some approach to avoid the copy?

3 Likes
4 Likes

Thank you! Seems quite unfortunate that SwiftUI relies on willSet.

1 Like