Search results for

NSPersistentCloudKitContainer

589 results found

Post

Replies

Boosts

Views

Activity

NSPersistentCloudKitContainer: How to re-fetch a record from CloudKit?
Is there a way to ask NSPersistentCloudKitContainer to update a local managed object’s values by refetching them from CloudKit? Here is my scenario: Let’s say I have a simple Address Book app that stores first name, last name, and phone number. I use NSPersisentCloudKitContainer to sync the data across a user’s devices. Let’s say a user installs the app on their iPhone and iPad. They add a bunch of records. All is working well. Now, I create version 2 of the app that adds a Notes field. The user installs version 2 on their iPhone, but have not updated their iPad yet. The user then adds some notes to existing records. Obviously, the user’s iPad will not download these notes since they have not updated to the version of the app that supports that field. Now, when the user finally installs version 2 of the app on their iPad, I want to ask NSPersistentCloudKitContainer to fetch the notes fields for the records that have been updated. However, I don’t see a way to do this. Of course, I could get
1
0
972
Jun ’21
How to get NSPersistentCloudKitContainer to sync in background
Is it possible for an app using NSPersistentCloudKitContainer to enable sync in the background, if so, how? Install app on your iPhone and iPad, create some data, it automatically syncs to both and life is good Close the iPad app Modify the data on iPhone Desired behavior: The backgrounded iPad app should sync (even if it takes a while) and be informed that its local database has finished syncing or similarly that changes were made. The use case is I want to reload my widget when data changes so it's up-to-date, so I need my app to sync it in the background, then notify when it's complete to be able to trigger the widget reload. I am concerned it will be a poor widget experience if it's always showing stale data until they manually open the app to initiate sync - kind of defeats the purpose of widgets. ha According to this post, they found sync is never run in the background. Is this not the case, or has it changed in iOS 15? Thanks!
2
0
1.7k
Jun ’21
How to migrate NSPersistentCloudKitContainer to App Group to access in Widget
I have shipped an app that utilizes Core Data in CloudKit viaNSPersistentCloudKitContainer. I now want to add a widget that can query for the current data to display. It's my understanding you need to migrate this to a new location available to a shared App Group. How do you do this? container = NSPersistentCloudKitContainer(name: AppName) container.loadPersistentStores { description, error in //handle error } container.viewContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy container.viewContext.automaticallyMergesChangesFromParent = true
1
0
1.4k
Jun ’21
Switching from production to development database
Hello! I have a live app in the appstore which uses NSPersistentCloudKitContainer. When I was working on the app, whatever data was created while testing was reflecting in the Development section of the CloudKitDashboard. Then, when time came for releasing the app, I had pushed my schema to production and everything has been working well. Recently, I have been working to make some changes in my code and while testing I realised that that I am being pointed to Production. Now how do I move back to using Development while working on the app. I have tried changing values of in .entitlement file. But it still does not give me what I want. Below is my entitlement values: aps-environment development com.apple.developer.icloud-container-environment Development com.apple.developer.icloud-container-identifiers Does anyone have any suggestions?
0
0
489
Jun ’21
NSPersistentCloudKitContainer support for CloudKit Record Zone Sharing
NSPersistentCloudKitContainer now supports sharing via CloudKit Record Zone Sharing. This new capability allows applications to easily build features that enable sharing of Core Data managed objects with multiple iCloud users. We've updated our sample application and documentation to demonstrate how these new capabilities work. At a high level NSPersistentCloudKitContainer now supports: New API for binding directly to call sites commonly used for sharing in your AppDelegate, UICloudSharingController, or your user interface code. Assigning the .shared database scope to instances of NSPersistentCloudKitContainerOptions Sharing of managed objects to single CKRecordZone Direct access to read or write the CKShare for a managed object via new API on NSPersistentCloudKitContainer. For more information be sure to watch our session Build apps that share data through CloudKit and Core Data on Friday.
1
0
858
Jun ’21
How can I get NSPersistentCloudKitContainer working with UICollectionViewDiffableDataSource
I am trying to get CoreData(Sync'd via NSPersistentCloudKitContainer, although that is not particularly relevant for the current issue) to play nicely (or even at all) with UICollectionViewDiffableDataSource. The stumbling block seems to be concerned with [NSManagedObject hash]. I need the diffing engine to notice a change when there is a change in the specific managedObject-subclass, AND/OR (at least some) of its child managedObject-subclasses. Example: So, in the above example object graph, I need the Posts datasource to notice when the 'name' of the Tag changes, and react accordingly. i.e. {Post.tags.any.name} The simplest solution would be if I could override[Post hash], but of course that's not allowed. Even obj-c method-swizzling does not work without complaining. Class 'Post' for entity 'Post' has an illegal override of NSManagedObject -hash Adding 'computed values' with the parent managed-object does not work; computed vars don't seem to be included in the [hash] implementation. Any ideas wha
0
0
813
Jun ’21
CloudKit CoreData not syncing on WatchOS
I have a watchOS extension that I'm trying to sync to their iPhone using CoreData and CloudKit, but it doesn't seem to want to sync. I've tried a few solutions (CloudKit + CoreData on iOS and watchOS sync not working, Core data + CloudKit - sharing between iOS and watchOS companion app), but it's still not syncing. Here's my shared (it's loading in both targets) persistence code: import CoreData struct PersistenceController { static let shared = PersistenceController() static var preview: PersistenceController = { let result = PersistenceController(inMemory: true) return result }() let container: NSPersistentCloudKitContainer init(inMemory: Bool = false) { container = NSPersistentCloudKitContainer(name: My-app) if inMemory { container.persistentStoreDescriptions.first!.url = URL(fileURLWithPath: /dev/null) } let description = container.persistentStoreDescriptions.first description?.cloudKitContainerOptions = NSPersistentCloudKitContainerOptions(containerIdentifier: iCloud.com.mydomain.my-app
1
0
1.8k
May ’21
CoreData • How to perform Lightweight-Migration when using NSPersistentCloudKitContainer?
I am developing an App using CoreData & CloudKit (NSPersistentCloudKitContainer). I am working on an App Update which includes an Update to the CoreData Model. I have created a new Model Version and applied the Changes (including new Properties & Relationships as well as Renaming of Entities & Properties). For Renaming I set the Renaming ID to the old Entity- / Property-Name. These Changes should be supported by Lightweight-Migration. Questions Is there anything else I have to consider when updating a CoreData Model or did I cover all? What about the CloudKit Synchronization? How does CloudKit handle the CoreData Model Update? I read about adding this Method *(initializeCloudKitSchemaWithOptions)* during Development and removing it when deploying to Production. What does this Method do exactly? Thanks a lot for your help in Advance. This is quiet a huge Update and the App does have an existing Userbase, so Migration-Problems are no Option;)
0
0
903
May ’21
Cloudkit Share Updating Core Data NSManaged Objects
I have a simple shopping list app that is using Core Data with Cloudkit. A user creates a list then adds items to the list. The list can be shared to other users. Core Data is first used to save the Lists and Items as NSManaged Objects. A list is then shared to another user who can add to items to the list, and both users working on the same list stay in sync with each other. This is all mostly working but I am having some trouble getting Core Data to update the locally stored NSManaged objects with changes from the Cloud Kit Share. Currently the app is dealing with a mix of NSManaged Objects and CKRecords to display in the table View that shows the items on a list. Which is a bit messy. I really want to just work with NSManaged Objects with Cloudkit doing the work of keeping things in sync between the 2 users. When User B adds an Item it successfully saves to the Shared Database and sets the parent as the list that was shared. This is where I get a bit stuck as I want User A to see the Item that User B added
0
0
701
Apr ’21
NSPersistentCloudKitContainer - how to reset CoreData+CloudKit after failed automatic migration (while still in development environment)
I have expanded my CoreData model quite a few times, including renaming entities, properties (and as far as I remember relationships). I am still working in the (CloudKit) development environment, only. Now I am getting errors each time I start the app (one line out of many shown): CoreData: debug: CoreData+CloudKit: -PFCloudKitMetadataModelMigrator calculateMigrationStepsWithConnection:error:(404): Skipping migration for 'ANSCKDATABASEMETADATA' because it already has a column named 'ZLASTFETCHDATE' The app is working as expected, it seems this error has no effect on correct CoreData+CloudKit execution. But I want to get rid of this error warning before I deploy to production for TestFlight or expand CoreData further. To have a clean CD+CK base I can start migrations from in future. Can I just reset CD (or CoreData's model) to make CD accept the current model as the base model without any migrations attached to it? An Apple Engineer suggested here - https://developer.apple.com/forums/thread/47637?answerId=146
3
0
2.9k
Apr ’21
Reply to Is it safe to use a NSPersistentCloudKitContainer on a Share Extension?
Having used this API for two of my apps, and speaking with an Apple engineer, it sounds like we can assume the following: NSPersistentCloudKitContainer can be safely used in a Share Extension for storing data locally. It will complete the save operation locally. Uploading to CloudKit requires a scheduled background operation on the part of the API. Because of this, by the time the Extension is terminated, the background operation is not completed, and thus the CloudKit sync does not occur. In my testing, this leads to predictable behavior: Data is never uploaded from an Extension, however, Data is saved locally in your persistent container. And upon launching your app, with the container alive once more, it will sync your data to CloudKit. It's a bit unwieldy having to launch your app after an operation in an Extension, but from my own usage, I think it's safe to say that you can safely use NSPersistentCloudKitContainer, even if it doesn't sync as you or I would like. I truly hope this behav
Topic: App & System Services SubTopic: Core OS Tags:
Apr ’21
Using Core Data With CloudKit
Hi, I have NSPersistentCloudKitContainer and everything is great until I faced the issue after a while of using it. It takes so long to sync because its loading all the changes that was done on the object and doesn't just fetch the latest values of the object. My solution now is to manually fetch CKRecords to see if there is something or not. If so I'm displaying Loading while CoreData and CloudKit find their way to sync. Thanks
0
0
560
Apr ’21