I think I've finally figured out what's going on, but I'm at a loss for how I would be able to guess this subtlety from the code or the documentation.
I believe what is happening is that, as was noted in the session, quakes has a mutable getter ("changes to the request are committed whenever the results getter is called"). So if you wrote the obvious code:
// This is fine because quakes hasn't changed yet
quakes.sectionIdentifier = sortBy.section
// This would apply the `sectionIdentifier` change and trigger an unnecessary fetch (?)
quakes.sortDescriptors = sortBy.descriptors
So the recommended code avoids this by only touching the property wrapper once. Despite quakes and config both being structs, they have reference semantics. But despite both referencing the same "object," they have different access semantics due to the property wrapper.
This seems incredibly subtle, contrary to standard Swift value/reference semantics, and unmentioned in the documentation. Am I understanding it correctly? Is there any way I should be able guess this behavior?
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: