Search results for

NSPersistentCloudKitContainer

589 results found

Post

Replies

Boosts

Views

Activity

Reply to WidgetKit and CoreData/CloudKit
In testing today, syncing in the background with NSPersistentCloudKitContainer seems to be working more reliably with the iOS 16 SDK. The first time you change something on another device it still seems to schedule a task to perform that work with utility priority (via -[NSCloudKitMirroringDelegate checkAndScheduleImportIfNecessary:andStartAfterDate:] which logs Scheduling automated import with activity CKSchedulerActivity priority 2 Utility), so it doesn't execute right away. If you change it again then I'm seeing it does immediately import the two accumulated changes (NSCloudKitMirroringDelegate Beginning automated import - ImportActivity - in response to activity, then -[PFCloudKitImportRecordsWorkItem applyAccumulatedChangesToStore:inManagedObjectContext:withStoreMonitor:madeChanges:error:] followed by NSCloudKitMirroringImportRequest Importing updated records) which triggers NSManagedObjectContextObjectsDidChange, NSPersistentStoreRemoteChange, and NSPersistentCloudKitContainer.eventChangedNotif
Jun ’22
Core Data Entity Inside Another Entity
So I have an entity in my core data model called recipe. I need to create another entity containing a recipe and a date that the recipe is assigned to. Can I do this similar to the way I've done it in the image and just save a Recipe object in the initialization of PlannedRecipe object in the Persistence file? Basically I just need to know how to add a entity in an entity using this core data model and persistence file. Persistence file: import CoreData struct PersistenceController { static let shared = PersistenceController() let container: NSPersistentCloudKitContainer init(inMemory: Bool = false) { container = NSPersistentCloudKitContainer(name: ReciPrep) if inMemory { container.persistentStoreDescriptions.first!.url = URL(fileURLWithPath: /dev/null) } container.loadPersistentStores(completionHandler: { (storeDescription, error) in if let error = error as NSError? { fatalError(Unresolved error (error), (error.userInfo)) } }) container.viewContext.automaticallyMergesChangesFromParent = tru
2
0
1.2k
Jun ’22
Reply to Good tutorial for hooking CloudKit into a SwiftUI project.
If anyone is curious the first part of a post (https://www.andrewcbancroft.com/blog/ios-development/data-persistence/getting-started-with-nspersistentcloudkitcontainer/) got me started and then the Apple Documentation - specifically Setting Up Core Data with CloudKit to me the rest of the way. I mostly jumped around the documentation from there (got data loading when I started the app) and then Hacking with Swift got me the rest of the way.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’22
NSPersistentCloudKitContainer: Exclude Relationship From Share
I am trying to add CloudKit sharing to my app using the new iOS 15 share method https://developer.apple.com/documentation/coredata/nspersistentcloudkitcontainer/3746834-sharemanagedobjects In the app there are 3 core data entities (Folder, Item, Comment) with the following relationships: A Folder contains many Items An Item has many Comments I want to use CloudKit to share just the Item entity, not any of its relationships. Is this possible to do with the share(_:to:completion:) method? Currently, when I pass an Item to the share method it also includes the Folder and Comments in the CKShare. How do I prevent this? A similar question was posted here with no response: https://developer.apple.com/forums/thread/697630
1
0
901
Jun ’22
Changing relationship delete rule & CloudKit
Hi, any side effect to be aware of when changing a core data relationship delete rule from Null to Cascade? I NSPersistentCloudKitContainer to handle CloudKit sync in case that's relevant. It doesn't look like any migration is required, and the cloudkit schema doesn't change so it seems there's nothing to do on the cloudkit-side either. However I'd prefer to double check to avoid making false assumptions. I wasn't able to find any documentation on that particular point so if someone can shade some light on how things work under the hood that would be appreciated. Thanks!
0
0
913
Jun ’22
Privacy Nutrition Label with encrypted CloudKit attributes
Situation I'm working on an app in which the user can manually enter in data. That data gets locally stored in a CoreData database and from there automatically synced (via NSPersistentCloudKitContainer) to the user private CloudKit database and I selected CloudKit encryption for every attribute. So as the developer I definitely can't access it, but it's stored on some remote server. Ambiguous Documentation The privacy site at https://developer.apple.com/app-store/app-privacy-details/ says stuff like: “Collect” refers to transmitting data off the device in a way that allows you and/or your third-party partners to access it for a period longer than what is necessary to service the transmitted request in real time. If you collect data about your app from Apple frameworks or services [such as MapKit, CloudKit, or App Analytics] you should indicate what data you collect and how you use it. You are not responsible for disclosing data collected by Apple. It's a bit unclear if Apple a third-party in this cas
0
0
934
Jul ’22
Are CKRecords Guaranteed to be Added to an NSPersistentCloudKitContainer Store in creationDate order?
I am trying to deduplicate data created by NSPersistentCloudKitContainer in my app. I have a universal app, with Share Extensions on both macOS and iOS. On each platform I share a store between the app and the extension with an App Group. The app and the extensions are both configured to sync to CloudKit. (This means local sharing is handled when offline, and a remote share extension will sync to CloudKit work when the main app is closed) This configuration is causing duplicates to be generated. I believe this is because when the macOS app is open, both it and the macOS share extension will try and (almost simultaneously) sync a newly shared object, resulting in two copies in CloudKit. On the macOS app, I can look through the persistent history and see the insertion 'author'. The first insertion is made by the extension macOSShareExtension, the second is made by NSCloudKitMirroringDelegate.import. I could easily make a choice to delete the second object. However, at the same time, on the iOS app, I w
2
0
962
Jul ’22
Reply to CoreData+CloudKit custom Zone
Are you using manually syncing your CloudKit with CoreData or are you using NSPersistentCloudKitContainer? If you using NSPersistentCloudKitContainer does the syncing for you, don't have to set any custom zone, it would set a custom zone automatically. If you are doing it manually, then you would need to set a custom zone when you are saving a record and when you are retrieving it not while loading the container's persistent stores (which is what you are doing).
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’22
Reply to Error: Failed to sync user keys in simulator
Problem 1: NSPersistentCloudKitContainer doesn't seem to work on simulator Solution: Use device, haven't found a way to make it work on the simulator. Problem2 When using CloudKit APIs (not NSPersistentCloudKitContainer) on the simulator I was getting CKError.notAuthenticated even though I had signed into iCloud on the simulator Root cause This happens when 2FA was enabled on the iCloud account but the 2FA code was asked on the simulator Solution Go to https://appleid.apple.com/, select devices on the sidebar Remove simulator (I found 2 simulators, removed both) Reset Xcode simulator Log into iCloud on the simulator Run the app Hopefully that should work.
Aug ’22
Swift Concurrency, Core Data, "partially thread-safe" types & Sendable conformance
Hi, Xcode warns me that NSPersistentContainer, NSManagedObjectContext, NSPersistentHistoryTransaction and NSPersistentHistoryToken are non-Sendable types and therefore cannot cross actor boundaries. These warnings occur even when I use @preconcurrency import CoreData (only works with Xcode 14.0 Beta, in Xcode 13.4.1, it says '@preconcurrency' attribute on module 'CoreData' is unused) I understand that types in Core Data have yet to be marked as Sendable when it makes sense. Although NSPersistentHistoryTransaction, and NSPersistentHistoryToken are reference types, they should qualify to be marked as Sendable in the future since these are immutable types, am I right? NSPersistentContainer provides variables and methods like viewContext and newBackgroundContext(). It would make sense that this type is thread-safe. However, I'm not sure about it, especially regarding its loadPersistentStores(completionHandler:) method. Is NSPersistentContainer (and its subclass NSPersistentCloudKitContainer) thread-safe
4
0
3.3k
Aug ’22
Not receiving Persistent Store Remote Change Notification.
Before the code... CloudKit, background mode (remote notifications) and push notifications are added to Capabilities. Background sync is working fine and view loads current store on manual fetch. Code that initialises the persistent container in app delegate... - (NSPersistentCloudKitContainer *)persistentContainer { // The persistent container for the application. This implementation creates and returns a container, having loaded the store for the application to it. @synchronized (self) { if (_persistentContainer == nil) { _persistentContainer = [[NSPersistentCloudKitContainer alloc] initWithName:@Expenses]; [_persistentContainer loadPersistentStoresWithCompletionHandler:^(NSPersistentStoreDescription *storeDescription, NSError *error) { if (error != nil) { __block NSPersistentStoreDescription *sDescription = storeDescription; dispatch_async(dispatch_get_main_queue(), ^(){ [sDescription setOption:[NSNumber numberWithBool:YES] forKey:@PersistentHistoryTracking]; [sDescription setOption:[NSNu
4
0
1.8k
Aug ’22
Reply to Not receiving Persistent Store Remote Change Notification.
By mistake i set the store descriptions inside if (error ! = nil) I changed that... yet no go... - (NSPersistentCloudKitContainer *)persistentContainer { // The persistent container for the application. This implementation creates and returns a container, having loaded the store for the application to it. @synchronized (self) { if (_persistentContainer == nil) { _persistentContainer = [[NSPersistentCloudKitContainer alloc] initWithName:@Expenses]; [_persistentContainer loadPersistentStoresWithCompletionHandler:^(NSPersistentStoreDescription *storeDescription, NSError *error) { if (error != nil) { #ifdef DEBUG NSLog(@Unresolved error %@, %@, error, error.userInfo); #endif abort(); } else #ifdef DEBUG NSLog(@Store successfully initialized); #endif [storeDescription setOption:[NSNumber numberWithBool:YES] forKey:@PersistentHistoryTracking]; [storeDescription setOption:[NSNumber numberWithBool:YES] forKey:@NSPersistentStoreRemoteChangeNotificationOptionKey]; }]; } } return _persistentContainer;
Aug ’22
Reply to Not receiving Persistent Store Remote Change Notification.
I think in built constants have to be used for keys so i changed the code to following... - (NSPersistentCloudKitContainer *)persistentContainer { // The persistent container for the application. This implementation creates and returns a container, having loaded the store for the application to it. @synchronized (self) { if (_persistentContainer == nil) { _persistentContainer = [[NSPersistentCloudKitContainer alloc] initWithName:@Expenses]; [_persistentContainer loadPersistentStoresWithCompletionHandler:^(NSPersistentStoreDescription *storeDescription, NSError *error) { if (error != nil) { #ifdef DEBUG NSLog(@Unresolved error %@, %@, error, error.userInfo); #endif abort(); } else { #ifdef DEBUG NSLog(@Store successfully initialized); #endif [storeDescription setOption:[NSNumber numberWithBool:YES] forKey:NSPersistentHistoryTrackingKey]; [storeDescription setOption:[NSNumber numberWithBool:YES] forKey:NSPersistentStoreRemoteChangeNotificationPostOptionKey]; } }]; } return _persistentContainer
Aug ’22
Error when calling initializeCloudKitSchema
I am trying to setup my CloudKit schema from CoreData using the NSPersistentCloudKitContainer but getting an error when calling try container.initializeCloudKitSchema() The error: Error Domain=NSCocoaErrorDomain Code=134060 A Core Data error occurred. UserInfo={encounteredErrors=( Error Domain=NSCocoaErrorDomain Code=134406 Request '07443E71-32AC-4E63-A163-AAF940FE1AD6' was aborted because the mirroring delegate never successfully initialized due to error: UserInfo={NSLocalizedFailureReason=Request '07443E71-32AC-4E63-A163-AAF940FE1AD6' was aborted because the mirroring delegate never successfully initialized due to error: } )} My container is iCloud., and is reflected in the Entitlement file.
1
0
1.1k
Aug ’22