Post

Replies

Boosts

Views

Activity

Reply to PersistenceController and CloudKit
struct PersistenceController { static let shared = PersistenceController() let container: NSPersistentCloudKitContainer init() { container = NSPersistentCloudKitContainer(name: "MJ") guard let fileContainer = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.com.Jad.MJ")?.appendingPathComponent("MJ.sqlite") else { fatalError("Shared file container could not be created.") } let storeDescription = NSPersistentStoreDescription(url: fileContainer) storeDescription.setOption(true as NSNumber, forKey: NSPersistentHistoryTrackingKey) storeDescription.setOption(true as NSNumber, forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey) storeDescription.cloudKitContainerOptions = NSPersistentCloudKitContainerOptions(containerIdentifier: "YOUR containerIdentifier") container.persistentStoreDescriptions = [storeDescription] container.loadPersistentStores(completionHandler: { (storeDescription, error) in if let error = error as NSError? { fatalError("Unresolved error \(error), \(error.userInfo)") } }) container.viewContext.automaticallyMergesChangesFromParent = true container.viewContext.mergePolicy = NSMergeByPropertyStoreTrumpMergePolicy } }
Dec ’21
Reply to Siri Shortcuts with SwiftUI and Core Data
I tried to observe NSPersistentStoreRemoteChange like this: .onReceive(NotificationCenter.default.publisher(for: .NSPersistentStoreRemoteChange)) { notification in DispatchQueue.main.async { let predicate = items.nsPredicate items.nsPredicate = nil items.nsPredicate = NSPredicate(value: true) items.nsPredicate = predicate } } but the operation that I execute in the closure isn't efficient and gives me an issue: Publishing changes from background threads is not allowed; make sure to publish values from the main thread (via operators like receive(on:)) on model updates
Dec ’21
Reply to Siri Shortcuts with CoreData
import CoreData struct PersistenceController { static let shared = PersistenceController() let container: NSPersistentContainer init() { container = NSPersistentContainer(name: "SiriShort") guard let fileContainer = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.SiriShortcut2")?.appendingPathComponent("SiriShort.sqlite") else { fatalError("Shared file container could not be created.") } let storeDescription = NSPersistentStoreDescription(url: fileContainer) storeDescription.setOption(true as NSNumber, forKey: NSPersistentHistoryTrackingKey) storeDescription.setOption(true as NSNumber, forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey) container.persistentStoreDescriptions = [storeDescription] container.loadPersistentStores(completionHandler: { (storeDescription, error) in if let error = error as NSError? { fatalError("Unresolved error \(error), \(error.userInfo)") } }) container.viewContext.automaticallyMergesChangesFromParent = true container.viewContext.mergePolicy = NSMergeByPropertyStoreTrumpMergePolicy } }
Dec ’21
Reply to Collapse button NavigationView SideBar SwiftUI
Does your actual code show the collapse button ? Yes Here is a very similar code struct ContentView: View { var body: some View { NavigationView{ List{ NavigationLink { Text("Hello") } label: { Text("Hello") } NavigationLink { Text("World") } label: { Text("World") } } .navigationTitle("Test") } } } What I want to really achieve is the sidebar that is used in the iPad Settings app, if you know how to do that, it would be perfect. Thank You very much
Sep ’21
Reply to App increases size even if I delete data (Core Data)
You should probably have to recreate the database completely, just keeping existing records. If you can explain better your solution it would be better for me In any case, does this cause you problem or is this for understanding ? It does not create me a direct problem, however I want to find a solution, because if you think about it, if you add and delete data every day for 100 days, even if there is no data (in the app) there will be a lot of MB occupied by the app in the iPhone Storage. Thank You!
Aug ’21