Post

Replies

Boosts

Views

Activity

Scrolling Table with children in SwiftUI for macOS app
How do I scroll to a row and select it when it is part of collapsed rows in Table ScrollViewReader { scrollViewProxy in Table([node], children: \.children, selection: $selectedNodeID) { TableColumn("Key") { Text($0.key) } TableColumn("Value") { Text($0.val) } } .onChange(of: selectedNodeID) { _, newValue in withAnimation { scrollViewProxy.scrollTo(newValue) } } } The code above works well for the rows that are expanded or at the root level. However, for the rows that are not yet expanded the code above does nothing. How can I update the code so that it scrolls to a row that has not materialized yet. Info: This is a macOS app I am on macOS 15.1.1 with Xcode 16.1 and the minimum target of the app is macOS 15
0
0
167
Nov ’24
NSPersistentCloudKitContainer losing data
Some users of my app are reporting total loss of data while using the app. This is happening specifically when they enable iCloud sync. I am doing following private func setupContainer(enableICloud: Bool) { container = NSPersistentCloudKitContainer(name: "") container.viewContext.automaticallyMergesChangesFromParent = true container.viewContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy guard let description: NSPersistentStoreDescription = container.persistentStoreDescriptions.first else { fatalError() } description.setOption(true as NSNumber, forKey: NSPersistentHistoryTrackingKey) description.setOption(true as NSNumber, forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey) if enableICloud == false { description.cloudKitContainerOptions = nil } container.loadPersistentStores { description, error in if let error { // Handle error } } } When user clicks on Toggle to enable/disable iCloud sync I just set the description.cloudKitContainerOptions to nil and then user is asked to restart the app. Apart from that I periodically run the clear history func deleteTransactionHistory() { let sevenDaysAgo = Calendar.current.date(byAdding: .day, value: -7, to: Date())! let purgeHistoryRequest = NSPersistentHistoryChangeRequest.deleteHistory(before: sevenDaysAgo) let backgroundContext = container.newBackgroundContext() backgroundContext.performAndWait { try! backgroundContext.execute(purgeHistoryRequest) } }
3
0
498
Sep ’24