Search results for

NSPersistentCloudKitContainer

589 results found

Post

Replies

Boosts

Views

Activity

Reply to Migration of local core data to iCloud core data
No, unfortunately if you hadn't set true for key NSPersistentHistoryTrackingKey, they will never get it to cloud, they will stay only in your device. A workaround that I used and worked fine, is to add a property to all entities (I used cloudReady: Bool, and at the first run of the app, after you adopt NSPersistentCloudKitContainer, change that property to true for all entities. This will force iCloud to sync those objects.
Jun ’20
Is there any way to observe the sync status of an NSPersistentCloudKitContainer?
I believe that right now there's no way to be notified when the sync status of an NSPersistentCloudKitContainer changes. Is my assumption correct? I'd like to know if there are pending changes to be synced or when the sync starts/ends to be able to reflect it on the UI to inform my users. Any ideas on how (or if it's possible) to achieve what I need? Thank you!
1
0
1.1k
Jul ’20
CloudKit corruption using NSPersistentCloudKitContainer
After many months/years of trying to create my own CoreData/iCloud sync engine, and getting about 90% of the way there; I gave up and started using NSPersistentCloudKitContainer, forcing us to drop support for iOS 12-. At first all seemed fine, however, today it all went horribly wrong (still investigating why) I now have 'duplicate' CKRecords of single ManagedObjects in CloudKit, and (it seems, although still tracking down the model) disconnected 'references'. Having looked at CloudKit Dashboard is seems that NSPersistentCloudKitContainer does not use ANY references, but simply a String of the UUID of the referenced CKRecord. I can only presume that this is a workaround to prevent Referencing a (not yet) non-existent CKRecord. So, this presents several questions: Is the lack of CKReference by design, or a bug? What defensive programming is in place to prevent duplications or corrupt references when using Stringly-Typed pseudo-references? Is there a way to inform the NSPersistentCloudKitContainer
2
0
994
Jul ’20
Detect/Receive CloudKit CoreData Errors
In development I've switched to NSPersistentCloudKitContainer and have begun the terrifying process of trying to test as many scenarios as possible to make sure nobody loses any data. During some testing I saw an error like this: I was able to fix this, but it was only affecting some scenarios and if this had happened to a real user they (and I) would never have known about the problem, and their data would not have synced to CloudKit. If the store fails to load you get an error, but if it loads but doesn't sync you don't. So my question is: is there a way to receive these kind of errors in code? I have looked for notifications and delegate methods and I can't find any.
1
0
1.2k
Jul ’20
Do unique constraints work on an NSPersistentCloudKitContainer?
The documentation - https://developer.apple.com/documentation/coredata/mirroring_a_core_data_store_with_cloudkit/creating_a_core_data_model_for_cloudkit for Creating a Core Data Model for CloudKit states that Unique constraints aren’t supported. but I've tried to set one up and it seems to be working fine (locally, I haven't tried syncing yet) on Xcode 11.5 & iOS 13.5. If I'm not mistaken, when NSPersistentCloudKitContainer was first introduced Xcode displayed an error if you tried to add a constraint to an Entity, but that doesn't seem to happen anymore. Has this restriction been lifted or do I just remember it incorrectly and it never showed any errors? If the restriction has not been lifted, does anyone know how to make sure that Entities are not duplicated? It'll be easy to add a cleanup operation after every sync, but so far I am not aware of any way to know when the sync has fully finished - https://developer.apple.com/forums/thread/652607. Thanks.
0
0
682
Jul ’20
WidgetKit + CoreData with CloudKit
Hi, I am developing an app with CoreData + CloudKit and wanted my Widget to fetch data from CloudKit to display. Everything is working on iOS / watchOS, but on WidgetKit the result from my fetch is always empty. I already configured the CloudKit capability on the Widget extension, then I am creating a new NSPersistentCloudKitContainer the and on public func timeline(with context: Context, completion: @escaping (Timeline<Entry>) -> ()) { I am trying to let cardsFetch = NSFetchRequest<Card>(entityName: Card) do { let cards = try persistentContainer.viewContext.fetch(cardsFetch) the result is always 0 and the same fetch on iOS returns the data. Is this supposed to work?
8
0
3.3k
Jul ’20
Health data like daily grams of protein in Core Data CloudKit container?
Hi, I wrote an app that helps me count how many grams of protein I eat each day. I'm the only user now, and the app uses Core Data and the CloudKit container, to sync data across my devices. I was thinking about releasing it in App Store, and I noticed this in the app review guidelines: may not store personal health information in iCloud. Does that mean we cannot use Core Data with NSPersistentCloudKitContainer for an app like this? Thanks.
0
0
395
Jul ’20
Reply to Persistent Storage for Previewing
I was able to fix this by moving my data store into its own class and using the same thing for both the app and previews: import CloudKit import CoreData import Foundation class DataStore { static let shared = DataStore() lazy var persistentContainer: NSPersistentContainer = { let container = NSPersistentCloudKitContainer(name: Structure) container.loadPersistentStores(completionHandler: { _, error in if let error = error { fatalError(Unresolved error (error)) } let context = container.viewContext context.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy context.automaticallyMergesChangesFromParent = true // other setup here }) return container }() func saveContext() { let context = persistentContainer.viewContext if context.hasChanges { do { try context.save() } catch { fatalError(Unresolved error (error)) } } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’20
Migrating iOS 13 app to 14: how to manage AppDelegate context code for CoreData?
I'm in the middle of updating my app to only support iOS 14+ and am moving to the new @main app structure. I'm trying to figure out how to deal with code in my App and Scene Delegate: mainly code related to Core Data and CloudKit persistent container. Stuff like lazy var persistentContainer: NSPersistentCloudKitContainer = {...} and let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext context.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy context.automaticallyMergesChangesFromParent = true Where do I put this kind of stuff in the new @main world?
1
0
1.1k
Jul ’20
Outdated CKRecord on NSPersistentCloudKitContainer.record(for:)
Hi, I am trying to fetch CKShare for NSManagedObject. Firstly I get CKRecord for it using NSPersistentCloudKitContainer's record(for:) method. And getting situation when: First time record(for:) gives correct CKRecord I successfully create CKShare, see it in online Dashboard Next time record(for:) gives old CKRecord which don't have share yet, it's outdated! I swipe down notification Notification Center or minimise the app (go to home screen), and when go back, database is being immediately updated and record(for:) returns correct CKRecord with existing share now. I can get correct CKRecord if I use only recordID from CKRecord that I get from record(for:), and fetch updated CKRecord using fetch(withRecordID:completionHandler:). But it increase awaiting time twice because I need to get response for correct CKRecord and then fetch CKShare for it. If no share for CKRecord, I could get that nil immediately but now I have to fetch correct updated CKRecord. So, anyone know how to keep local database update
0
0
464
Jul ’20
Reply to New toolbar appearance in macOS 11
So for any passers-by that are interested in how I eventually achieved this... (Credit to mtsrodrigues for how to deal with change of Scene in his answer in this thread... https://developer.apple.com/forums/thread/650876) My Core Data implementation for SwiftUI and the new App and Scene protocols and Window container! My SwiftUI App... struct MyApp: App { @Environment(.scenePhase) private var scenePhase @StateObject private var persistentStore = PersistentStore.shared var body: some Scene { WindowGroup { ContentView() .environment(.managedObjectContext, persistentStore.context) } .onChange(of: scenePhase) { phase in switch phase { case .active: print((#function) REPORTS - App change of scenePhase to ACTIVE) case .inactive: print((#function) REPORTS - App change of scenePhase to INACTIVE) case .background: print((#function) REPORTS - App change of scenePhase to BACKGROUND) savePersistentStore() @unknown default: fatalError((#function) REPORTS - fatal error in switch statement for .onChange modifier) } } } func
Topic: UI Frameworks SubTopic: General Tags:
Jul ’20
Reply to Using Core Data with SwiftUI App Protocol
My two cents... My Core Data implementation for SwiftUI using the new App and Scene protocols and Window container! Credit to: mtsrodrigues for how to deal with change of Scene in his answer in this thread. KrakenDev's article on how to write a one line singleton My SwiftUI App... import SwiftUI @main struct YourApp: App { @Environment(.scenePhase) private var scenePhase @StateObject private var persistentStore = PersistentStore.shared var body: some Scene { WindowGroup { ContentView() .environment(.managedObjectContext, persistentStore.context) } .onChange(of: scenePhase) { phase in switch phase { case .active: print((#function) REPORTS - App change of scenePhase to ACTIVE) case .inactive: print((#function) REPORTS - App change of scenePhase to INACTIVE) case .background: print((#function) REPORTS - App change of scenePhase to BACKGROUND) savePersistentStore() @unknown default: fatalError((#function) REPORTS - fatal error in switch statement for .onChange modifier) } } } func savePersistentStore() { persiste
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’20
Reply to Is there any way to observe the sync status of an NSPersistentCloudKitContainer?
I've seen that the documentation of NSPersistentCloudKitContainer has been updated after the WWDC with two new Type Properties: class let eventChangedNotification: NSNotification.Name and class let eventNotificationUserInfoKey: String I think that are related to your question but I haven't tried them. I'm looking for this feature from the last year and I hope that in iOS 14 it will be implemented.
Jul ’20