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!
Topic: App & System Services SubTopic: iCloud Tags:
Nov ’24
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:
Replies
Boosts
Views
Activity
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:
Replies
Boosts
Views
Activity
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:
Replies
Boosts
Views
Activity
Aug ’25
Reply to Persist OSLog in "Analytics & Improvements"
From the looks of it, I need to implement the following. Apple don't have the facility for the items below. use the Logger api for logging and writing to the system log use OSLogStore on a separate thread to write to disk in my app space collect the log and analyze the performance issue
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Dec ’24
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!
Topic: App & System Services SubTopic: iCloud Tags:
Replies
Boosts
Views
Activity
Nov ’24