Avatar
あと、今見つけられないのですが、前に shiz さんが値型の @Observable には問題があるという意見をコアチームの誰かが発言してるフォーラムの投稿を挙げてくれてた気が・・・。
このあたりの話ですかね? 正しく理解できていないかもしれませんが... @Observable なstructの値を参照型が保持していて、その値のコピーが変更された場合に元の値のサブスクライバーにも変更が通知されてしまうのが問題で、これはCoWを使えば解決できそうだけど、そもそもの値型の概念やエッジケースがありそうだから後で考える、というようなことを言っているのかなと思ってます。 https://forums.swift.org/t/second-review-se-0395-observability/65261/113 https://forums.swift.org/t/second-review-se-0395-observability/65261/119
(edited)
To circle back on the structural nature of observable types - there are definitely use cases for things to be able to be Observable and interplay with observation that are structures; however as folks have raised there are some sharp edges. Namely of which - what happens when you copy a structure that is marked with @Observable. To go into this ...
Making the observation tracking data copy-on-write for value types seems better than making it truly shared, but it still doesn't seem right. I don't think I can explain what I see as the right thing here without a little bit of theory. I think folks might be confusing values and locations. These are both basic formal concepts of languages, t...