Post

Replies

Boosts

Views

Activity

Reply to Preview Crashes when using @FetchRequest
I got a similar issue when moving from a class with lazy vars for preview and production containers to init(inMemory: Bool) way of doing it. I figured out that it was because I had let persistenceController = PersistenceController.shared in my App, which I later passed to the .environment(.managedObjectContext). In my case it also makes sense to use a "similar workaround" to DRY up a bit the @FetchRequests. It looks like the best place is the extension that has @nonobjc public class func fetchRequest() -> NSFetchRequest for each Core Data entity.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
6h
Reply to Sample Code with Swift 6
On the CoreData / CloudKit one (https://developer.apple.com/documentation/coredata/sharing-core-data-objects-between-icloud-users) - I've found that NSManagedObjectContext is sendable (https://fatbobman.com/en/posts/sendable-nsmanagedobjectcontext/). From it I can get the persistence controller, and from it I get the stores and this solves the Swift 6 migration path and looks good. @DTS Engineer What would you say about such approach?
Topic: Programming Languages SubTopic: Swift Tags:
3d
Reply to Core Data Multiple NSEntityDescriptions claim the NSManagedObject subclass
Hi everyone! Is there an update on this issue or the posted feedback? I still run into the same in with the Xcode 25.5 RC and iOS 26.5 RC. What I do is: Rename the first model from Model to ModelV1 Copy the ModelV1 to ModelV2 Add new properties in ModelV2 Create NSStagedMigrationManager All entities are with manual/none generation. As I've already introduced usage of into: context when creating new objects, they are fine. Now the @FetchRequests fail (the one the views) with: Thread 1: "executeFetchRequest:error: A fetch request must have an entity.". These are 'solvable' by creating a FetchRequest with an entity: https://developer.apple.com/documentation/swiftui/fetchrequest/init(entity:sortdescriptors:predicate:animation:). However this requires passing around the context and adding inits in a lot of places. These are two WWDC meetings with more info: https://developer.apple.com/videos/play/wwdc2023/10186 https://developer.apple.com/videos/play/wwdc2022/10120 However they don't contain clues what might be needed.
Topic: App & System Services SubTopic: iCloud Tags:
May ’26
Reply to Charts performance issue
The solution is describe here: https://developer.apple.com/forums/thread/763757. The x axis marks are causing the issue. I was able to implement a solution by following the suggested code. Now I don't have a performance issue when scrolling in charts.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’26
Reply to Charts performance issue
Hi everyone, I observe similar performance issue. They performance is degraded when the x axis domain is enlarged. I add 5 bars per day, and around 150 days there is a visible jitter and tearing while dragging. I've tried various techniques to improve it such as large xAxis and displaying events only around the scroll position, however as noted above using it lowers the performance. I've also tried prepending and apending days, without having a large x axis domain, but this makes the scroll position jump. Here is another code sample. import Charts import SwiftUI struct PerformanceBarChart: View { struct DataPoint: Identifiable { let id = UUID() let date: Date let x: Int let yStart: Date let yEnd: Date let category: String } private var today = Date.now.startOfDay() @State private var data: [DataPoint] = [] @State private var scrollPosition: Date = Date.now @State private var loading = false @State var xAxisDomain: ClosedRange<Date> = Date.now...Date.now private let calendar = Calendar.autoupdatingCurrent private let visibleRange: TimeInterval = 7 * 24 * 60 * 60 private let chunkSize: Int = 30 var body: some View { VStack { Text("X Axis Domain Length: \(data.count / 5)") Text("Until 90 it is okay, after 150 lag is noticable.") HStack { Button("prepend") { generate() } .buttonStyle(.bordered) Text( "Scroll jumps if not at end. It cannot be controlled. There is no value change, only visual." ) } .padding() HStack { Button("set large x domain") { var startComponents = DateComponents() startComponents.year = calendar.component(.year, from: today) - 1 startComponents.month = 1 startComponents.day = 1 startComponents.hour = 0 startComponents.minute = 0 startComponents.second = 0 let start = calendar.date(from: startComponents)! xAxisDomain = start...data.last!.date } .buttonStyle(.bordered) Text( "X Axis stats from Jan 1st last year. Even if not data is added scrolling is slow." ) } .padding() Text(scrollPosition, format: .dateTime) Chart(data) { BarMark( x: .value("Date", $0.date, unit: .day), yStart: .value("Start", $0.yStart), yEnd: .value("End", $0.yEnd) ) .foregroundStyle(by: .value("Category", $0.category)) } .chartScrollableAxes(.horizontal) .chartXVisibleDomain(length: 7 * 24 * 3600) .chartXAxis { AxisMarks(values: .stride(by: .day)) { value in AxisGridLine() AxisTick() AxisValueLabel(format: .dateTime.day().month()) } } .chartXScale(domain: xAxisDomain) .chartYScale(domain: today.startOfDay()...today.endOfDay()) .chartScrollPosition(x: $scrollPosition) .chartScrollPosition(initialX: today) .frame(height: 450) .padding() .onAppear { generate() } } } private func generate() { let first = data.first let date = first?.date ?? today let x = first?.x ?? 1 var newPoints = [DataPoint]() newPoints.reserveCapacity(3 * chunkSize) for i in 1...chunkSize { let date = calendar.date(byAdding: .day, value: -i, to: date)! newPoints.append( DataPoint( date: date, x: x - i, yStart: todayAt(hour: 2, minute: 0), yEnd: todayAt(hour: 3, minute: 0), category: String(Int.random(in: 1...3)) ) ) newPoints.append( DataPoint( date: date, x: x - i, yStart: todayAt(hour: 4, minute: 30), yEnd: todayAt(hour: 6, minute: 30), category: String(Int.random(in: 1...3)) ) ) newPoints.append( DataPoint( date: date, x: x - i, yStart: todayAt(hour: 9, minute: 30), yEnd: todayAt(hour: 10, minute: 30), category: String(Int.random(in: 1...3)) ) ) newPoints.append( DataPoint( date: date, x: x - i, yStart: todayAt(hour: 15, minute: 30), yEnd: todayAt(hour: 17, minute: 30), category: String(Int.random(in: 1...3)) ) ) newPoints.append( DataPoint( date: date, x: x - i, yStart: todayAt(hour: 20, minute: 0), yEnd: todayAt(hour: 21, minute: 30), category: String(Int.random(in: 1...3)) ) ) } data.insert(contentsOf: newPoints.reversed(), at: 0) xAxisDomain = data.first!.date...data.last!.date } private func todayAt(hour: Int, minute: Int) -> Date { return calendar.date( bySettingHour: hour, minute: minute, second: 0, of: today )! } } #Preview { PerformanceBarChart() }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’26
Reply to Sample Code with Swift 6
For anyone interested in following the conversation it is here.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
6h
Reply to Preview Crashes when using @FetchRequest
I got a similar issue when moving from a class with lazy vars for preview and production containers to init(inMemory: Bool) way of doing it. I figured out that it was because I had let persistenceController = PersistenceController.shared in my App, which I later passed to the .environment(.managedObjectContext). In my case it also makes sense to use a "similar workaround" to DRY up a bit the @FetchRequests. It looks like the best place is the extension that has @nonobjc public class func fetchRequest() -> NSFetchRequest for each Core Data entity.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
6h
Reply to Sample Code with Swift 6
On the CoreData / CloudKit one (https://developer.apple.com/documentation/coredata/sharing-core-data-objects-between-icloud-users) - I've found that NSManagedObjectContext is sendable (https://fatbobman.com/en/posts/sendable-nsmanagedobjectcontext/). From it I can get the persistence controller, and from it I get the stores and this solves the Swift 6 migration path and looks good. @DTS Engineer What would you say about such approach?
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
3d
Reply to Sample Code with Swift 6
Thanks Quinn! I've added two feedbacks: FB23098055 and FB23098306.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
2w
Reply to Core Data Multiple NSEntityDescriptions claim the NSManagedObject subclass
Hi everyone! Is there an update on this issue or the posted feedback? I still run into the same in with the Xcode 25.5 RC and iOS 26.5 RC. What I do is: Rename the first model from Model to ModelV1 Copy the ModelV1 to ModelV2 Add new properties in ModelV2 Create NSStagedMigrationManager All entities are with manual/none generation. As I've already introduced usage of into: context when creating new objects, they are fine. Now the @FetchRequests fail (the one the views) with: Thread 1: "executeFetchRequest:error: A fetch request must have an entity.". These are 'solvable' by creating a FetchRequest with an entity: https://developer.apple.com/documentation/swiftui/fetchrequest/init(entity:sortdescriptors:predicate:animation:). However this requires passing around the context and adding inits in a lot of places. These are two WWDC meetings with more info: https://developer.apple.com/videos/play/wwdc2023/10186 https://developer.apple.com/videos/play/wwdc2022/10120 However they don't contain clues what might be needed.
Topic: App & System Services SubTopic: iCloud Tags:
Replies
Boosts
Views
Activity
May ’26
Reply to Charts performance issue
The solution is describe here: https://developer.apple.com/forums/thread/763757. The x axis marks are causing the issue. I was able to implement a solution by following the suggested code. Now I don't have a performance issue when scrolling in charts.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
May ’26
Reply to Charts performance issue
Hi everyone, I observe similar performance issue. They performance is degraded when the x axis domain is enlarged. I add 5 bars per day, and around 150 days there is a visible jitter and tearing while dragging. I've tried various techniques to improve it such as large xAxis and displaying events only around the scroll position, however as noted above using it lowers the performance. I've also tried prepending and apending days, without having a large x axis domain, but this makes the scroll position jump. Here is another code sample. import Charts import SwiftUI struct PerformanceBarChart: View { struct DataPoint: Identifiable { let id = UUID() let date: Date let x: Int let yStart: Date let yEnd: Date let category: String } private var today = Date.now.startOfDay() @State private var data: [DataPoint] = [] @State private var scrollPosition: Date = Date.now @State private var loading = false @State var xAxisDomain: ClosedRange<Date> = Date.now...Date.now private let calendar = Calendar.autoupdatingCurrent private let visibleRange: TimeInterval = 7 * 24 * 60 * 60 private let chunkSize: Int = 30 var body: some View { VStack { Text("X Axis Domain Length: \(data.count / 5)") Text("Until 90 it is okay, after 150 lag is noticable.") HStack { Button("prepend") { generate() } .buttonStyle(.bordered) Text( "Scroll jumps if not at end. It cannot be controlled. There is no value change, only visual." ) } .padding() HStack { Button("set large x domain") { var startComponents = DateComponents() startComponents.year = calendar.component(.year, from: today) - 1 startComponents.month = 1 startComponents.day = 1 startComponents.hour = 0 startComponents.minute = 0 startComponents.second = 0 let start = calendar.date(from: startComponents)! xAxisDomain = start...data.last!.date } .buttonStyle(.bordered) Text( "X Axis stats from Jan 1st last year. Even if not data is added scrolling is slow." ) } .padding() Text(scrollPosition, format: .dateTime) Chart(data) { BarMark( x: .value("Date", $0.date, unit: .day), yStart: .value("Start", $0.yStart), yEnd: .value("End", $0.yEnd) ) .foregroundStyle(by: .value("Category", $0.category)) } .chartScrollableAxes(.horizontal) .chartXVisibleDomain(length: 7 * 24 * 3600) .chartXAxis { AxisMarks(values: .stride(by: .day)) { value in AxisGridLine() AxisTick() AxisValueLabel(format: .dateTime.day().month()) } } .chartXScale(domain: xAxisDomain) .chartYScale(domain: today.startOfDay()...today.endOfDay()) .chartScrollPosition(x: $scrollPosition) .chartScrollPosition(initialX: today) .frame(height: 450) .padding() .onAppear { generate() } } } private func generate() { let first = data.first let date = first?.date ?? today let x = first?.x ?? 1 var newPoints = [DataPoint]() newPoints.reserveCapacity(3 * chunkSize) for i in 1...chunkSize { let date = calendar.date(byAdding: .day, value: -i, to: date)! newPoints.append( DataPoint( date: date, x: x - i, yStart: todayAt(hour: 2, minute: 0), yEnd: todayAt(hour: 3, minute: 0), category: String(Int.random(in: 1...3)) ) ) newPoints.append( DataPoint( date: date, x: x - i, yStart: todayAt(hour: 4, minute: 30), yEnd: todayAt(hour: 6, minute: 30), category: String(Int.random(in: 1...3)) ) ) newPoints.append( DataPoint( date: date, x: x - i, yStart: todayAt(hour: 9, minute: 30), yEnd: todayAt(hour: 10, minute: 30), category: String(Int.random(in: 1...3)) ) ) newPoints.append( DataPoint( date: date, x: x - i, yStart: todayAt(hour: 15, minute: 30), yEnd: todayAt(hour: 17, minute: 30), category: String(Int.random(in: 1...3)) ) ) newPoints.append( DataPoint( date: date, x: x - i, yStart: todayAt(hour: 20, minute: 0), yEnd: todayAt(hour: 21, minute: 30), category: String(Int.random(in: 1...3)) ) ) } data.insert(contentsOf: newPoints.reversed(), at: 0) xAxisDomain = data.first!.date...data.last!.date } private func todayAt(hour: Int, minute: Int) -> Date { return calendar.date( bySettingHour: hour, minute: minute, second: 0, of: today )! } } #Preview { PerformanceBarChart() }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
May ’26
Reply to CloudKit, CoreData and Swift 6 for sharing between users
I have found the solution for the app crash and now I have it with Swift 6, CoreData and CloudKit. The NotificationCenter.addObserver(_:selector:name:object:) is causing the crash. When changed to addObserver(forName:object:queue:using:) it is fine.
Topic: App & System Services SubTopic: iCloud Tags:
Replies
Boosts
Views
Activity
Feb ’26