Post

Replies

Boosts

Views

Activity

Reply to Finding source for SwiftData array behaviour
The question is about the content ordering of @Model array. The employee case, [Employee] will behave like a set. i.e. random ordering The [String] case, it will behave like a normal standard array. Where do I find this in any documentation? Do you have a link to this? Thanks in advance!
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’25
Reply to Ghost Padding on NavigationBarPlatterContainer
Here's an sample code that can produce the problem. It happens on rotate in simulator, only in iOS 26.* Expectation: should have the same lead spacing regardless of the rotation of the device. struct ContentView: View { @State private var showingSharePopover = false var body: some View { NavigationStack { VStack { Button { showingSharePopover = true } label: { Label("Show Share Options", systemImage: "square.and.arrow.up") .font(.title2) .padding(.vertical, 10) .padding(.horizontal, 20) } .buttonStyle(.borderedProminent) .tint(.indigo) .controlSize(.large) .shadow(radius: 5) .sheet(isPresented: $showingSharePopover, content: { }) } .navigationBarBackButtonHidden(false) .toolbar { ToolbarItem(placement: .topBarLeading) { Button { } label: { HStack { Image(systemName: "square.and.arrow.left") Text("Done") } } } } .padding() } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’25
Reply to Sharelink dismisses Parent View
Here's a sharelinkDropin for those who needs it. The following would not dismiss the presenting view when save to photos. // // SharelinkDropin.swift // import SwiftUI struct SharelinkDropin<Label: View>: View { let item: URL @ViewBuilder let label: Label @State var isPresented: Bool = false var body: some View { Button { self.isPresented.toggle() } label: { self.label } .sheet(isPresented: self.$isPresented, content: { ActivityViewController(activityItems: [self.item]) }) } } fileprivate struct ActivityViewController: UIViewControllerRepresentable { var activityItems: [Any] var applicationActivities: [UIActivity]? = nil func makeUIViewController(context: UIViewControllerRepresentableContext<ActivityViewController>) -> UIActivityViewController { let controller = UIActivityViewController(activityItems: activityItems, applicationActivities: applicationActivities) return controller } func updateUIViewController(_ uiViewController: UIActivityViewController, context: UIViewControllerRepresentableContext<ActivityViewController>) {} } #Preview { SharelinkDropin(item: URL.placeholderIcon, label: { Text("Share") }) }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’25
Reply to SwiftData ModelContext Fetch Crashing
let id = model.persistentModelID let descriptor = FetchDescriptor<cache>( predicate: #Predicate { $0.cacheOf.persistentModelID == id } // predicate: #Predicate { $0.cacheOf.id == id } or this ) let result = (try? self.modelContext.fetch(descriptor) // 💥 crash here! .first) return result Some update on this! So turns out, I was fetching a model that was just created. The system can't find the model. I guess this was a cache miss in swiftData?! To Fix This: In your modelActor try? self.modelContext.save() basically, you want the modelContext to write into disk to create the persistentModelID Good luck!
Nov ’24