In XCode 16.2 beta 3 the onPreferenceChange view modifier closure was changed to be @Sendable. This change caused a number of errors in my code when I try to use the value in the closure to update a view property.
I’ve attached a simple WidthReader example that shows these errors.
This change seems similar to the recent change to the alignmentGuide closure. The difference is the alignmentGuide closure is used to change the value of the alignment guide and I have no expectation of using it to update view properties. The onPreferenceChange closure returns no value and as far as I can figure the only use of it would be to modify view properties.
As a workaround I could wrap each modification in a main actor Task but I’m concerned about this somehow delaying my updates and causing visual glitches in the UI.
Ideally I would like the onPreferenceChange modifier to be annotated with @MainActor instead of @Sendable as I can’t see a use case when someone would use the value to update something off the main thread.
If this is not a bug and this closure will continue to be @Sendable and not @MainActor I would really like to know so I can update my Swift Packages accordingly to deal with this change.
Got another reply from Apple confirming this is operating as designed and that they will no longer monitor my feedback.