Post

Replies

Boosts

Views

Activity

Reply to SwiftData Model didset
It's somewhat I finally done in my code. But, for this to work, it's mandatory to use @Transient macro to tell Xcode the property is not persistent. This approach involves to "double" some properties, as you've done in your example. So, for your solution to work just add @Transient for the _selectedSheetID property and it'll work. Like this : @Model public final class importConfig: Identifiable, ObservableObject{ ... private var _selectedSheetID: UUID? @Transient var selectedSheetID: UUID? { get { return __selectedSheetID } set { // validation selectedSheetID = newValue } } } It allows to remove lots of .onChange logic in the view (and that logic should NOT be in the view), and better the "business logic" is in the model and wherever the model is used, you ensure the same behavior.
Dec ’23