Post

Replies

Boosts

Views

Activity

Reply to List selection does not update model on MacOS. But same code works fine on iOS.
Seems to be a bug or behavior quirk in NavigationStack, because if I change the code to use .sheet(), then it suddenly work fine on MacOs: import SwiftUI import Observation let allSelectables: [String] = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5"] @Observable class Model { var items: Set<String> = [] // Use Set for unique selections } struct ContentView: View { @State var model = Model() @State private var showSheet = false var body: some View { NavigationStack { VStack { Text("Selected: \(model.items.joined(separator: ", "))") List { Button("Go to Selection (\(model.items.count))") { showSheet = true } } .sheet(isPresented: $showSheet) { List(allSelectables, id: \.self, selection: $model.items) { item in Text(item) } #if os(iOS) .environment(\.editMode, .constant(.active)) // Enable multiple selection #endif } } } } }
Topic: UI Frameworks SubTopic: SwiftUI
3w
Reply to modelContext.fetch() hits assert on release builds, but not on debug builds
Instead of using addRecord with generics I switched to concrete type and it is not hitting assert() anymore: func addWorkspace(_ someDTO: WorkspaceDTO) async throws { var zone: ZoneModel? = nil let recordName = someDTO.recordNameType let fetchDescriptor = FetchDescriptor<WorkspaceModel> (predicate: #Predicate {$0.recordName == recordName}) var localEntitites: [WorkspaceModel] = try modelContext.fetch(fetchDescriptor) <---- no more crash here So it seems that Fetch Descriptor crashes only if I use it with generics. Not with concrete types. Anyway, seems like a bug in swiftData.
Feb ’25