Discussion
Loading...

Post

  • About
  • Code of conduct
  • Privacy
  • Users
  • Instances
  • About Bonfire
Konstantin 🔭
@konstantin@hachyderm.io  ·  activity timestamp 11 hours ago

@alpennec @squeakytoy wait, what does it mean equatable properties don't trigger updates? 🤔 #Swift #SwiftUI

  • Copy link
  • Flag this post
  • Block
Rick van Voorden
@vanvoorden@mastodon.social replied  ·  activity timestamp 3 hours ago

@konstantin @alpennec In some situations `Observable` is not able to perform this check for you. `Observable` generates code that dispatches statically at compile time to test for equality. If your `Observable` type *does not know* at compile time if these types are Equatable then it will not perform a dynamic runtime check for you. This can be one option to "opt out" of the equality checking.

https://forums.swift.org/t/understanding-when-swiftui-re-renders-an-observable/77876/

  • Copy link
  • Flag this comment
  • Block
Rick van Voorden
@vanvoorden@mastodon.social replied  ·  activity timestamp 3 hours ago

@konstantin @alpennec The other option I believe to opt out of equality checking is to provide *your own* `shouldNotifyObservers` method that returns `true`. I believe the macro will respect your method and will choose not to generate new ones.

https://github.com/swiftlang/swift/pull/78151

  • Copy link
  • Flag this comment
  • Block
Rick van Voorden
@vanvoorden@mastodon.social replied  ·  activity timestamp 3 hours ago

@konstantin @alpennec I understand the motivation for these changes… but I'm also torn. Because now we are performing a linear time operation to set collection properties. This is not always the right choice… but I can understand why it might be the right choice in many places. But I do think engineers should learn exactly what is happening and exactly how to opt out of this behavior if that would improve performance.

  • Copy link
  • Flag this comment
  • Block
Helge Heß
@helge@mastodon.social replied  ·  activity timestamp 10 hours ago

@konstantin @alpennec @squeakytoy@bird.makeup I think that values you set but didn’t actually change won’t trigger updates.
Like guard newValue != oldValue else return in the setter

  • Copy link
  • Flag this comment
  • Block
Axel Le Pennec
@alpennec@iosdev.space replied  ·  activity timestamp 5 hours ago

@helge @konstantin yep, I updated my post to be more explicit. Of course it triggers updates for Equatable properties, but only when the old and new value differ. Otherwise nothing is published, it’s ignored.

  • Copy link
  • Flag this comment
  • Block
Log in

bonfire.cafe

A space for Bonfire maintainers and contributors to communicate

bonfire.cafe: About · Code of conduct · Privacy · Users · Instances
Bonfire social · 1.0.0-rc.3.21 no JS en
Automatic federation enabled
  • Explore
  • About
  • Members
  • Code of Conduct
Home
Login