Search results for

NSPersistentCloudKitContainer

589 results found

Post

Replies

Boosts

Views

Activity

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
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
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 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
Reply to WidgetKit and CoreData/CloudKit
I don’t think this last comment is accurate, at least as of iOS 15. In digital lounges at WWDC Apple engineers explained it is possible for NSPersistentCloudKitContainer to sync while your app is open in the background. It seems though the work is scheduled with utility priority. In my testing it will sync if you make 4 changes - once enough updates are accumulated it’ll process them. But even then my widget is showing the changes from the 3rd update because it hasn’t yet finished updating it seems, and attempting to delay it causes the code not to execute I assume because iOS suspends the app again very soon after. So basically it may eventually sync in background, only if your app is already open in background, and it may not be reliable and your widget might not get the most up-to-date data. Maybe this can be improved by utilizing background task API, that’s what they suggested trying in the digital lounge. Do note they also said NSPersistentCloudKitContainer does not support multi-proces
Jun ’22
NSPersistentCloudKitContainer questions
I use NSPersistentCloudKitContainer to synchronize data between iOS and macOS. After installing the app, it takes long (sometimes up to an hour) for all data to become available. Related to this, I have a few questions: Synchronization seems only to take place when the app runs in the foreground. Is there a way to keep the app synchronizing when it is brought to the background? I have enabled remote notifications and use registerForRemoteNotifications in my app delegate (via UIApplicationDelegateAdaptor). I haven't yet experimented with background processing. Should I do that, and can you point me to some references? Is there a way to check whether the local-stored data matches what's available on the server? E.g. checking whether a (local-stored) NSPersistentHistoryToken matches the latest NSPersistentHistoryToken on the server. Internally NSPersistentCloudKitContainer knows, as I can see log events popping up saying that there are no new data to mirror. I would like to know this to inform
0
0
986
Jun ’22
What are some reliable mechanism to prevent data duplication in CoreData CloudKit?
Every of our data row, contains an unique uuid column. Previously, before adopting CloudKit, the uuid column has a unique constraint. This enables us to prevent data duplication. Now, we start to integrate CloudKit, into our existing CoreData. Such unique constraint is removed. The following user flow, will cause data duplication. Steps to cause data duplication when using CloudKit Launch the app for the first time. Since there is empty data, a pre-defined data with pre-defined uuid is generated. The pre-defined data is sync to iCloud. The app is uninstalled. The app is re-installed. Launch the app for the first time. Since there is empty data, a pre-defined data with pre-defined uuid is generated. Previous old pre-defined data from step 3, is sync to the device. We are now having 2 pre-defined data with same uuid! :( I was wondering, is there a way for us to prevent such duplication? In step 8, we wish we have a way to execute such logic before written into CoreData Check whether such uuid exists in CoreData
1
0
1.3k
Jun ’22
icloud-container-environment with NSPersistentCloudKitContainer
The com.apple.developer.icloud-container-environment provides the option to set the development or production environment to use for the iCloud containers. My app uses Core Data, and I have implemented NSPersistentCloudKitContainer. When I am not working on schema changes, I would like my local development builds to still access the production Core Data store. However, setting this entitlement to Production has not produced this result... the container is still listed as 'Staging' and I can see in the CloudKit Console that the Development container is being used. Does this entitlement only apply to direct use of CloudKit, and not to NSPersistentCloudKitContainer? If it doesn't apply to the latter, is there another way to direct NSPersistentCloudKitContainer to use the Production container? This is an iOS app though I am beginning work on a macOS version and would like to be able to do this in both environments.
1
0
2.7k
Jun ’22
Advice on sharing data between apps NSPersistantCloudkit container or App groups or both?
I have several different apps that I'd like to share a personal core data store with on the same device and across devices. I've been experimenting with NSPersistentCloudKitContainer, which seems to work, but it can take a while to sync and it's not clear when it has. I have also experimented with using app groups where the SQLite file is placed in the app group so that changes are immediately available to other apps on the device. My question is whether it is better to do one or the other or both. Will two apps open on the same device accessing the shared SQLite cause conflict issues? Do I even need to sync data with cloudKit if I'm already syncing with a shared group? Using NSPersistentCloudKitContainer alone means that each app will be syncing its own copy of the data locally, which doesn't seem very efficient and again I don't know if it's synched when I open the other app up. But I have seen conflicts when i have both apps open at the same time. Is there a foolproof way to prevent confl
0
0
702
Jun ’22
Data Persistence using Core Data
So I created a program without selecting “use core data” and realized after trying to make a persistence data storage that it helps very much so I created a new program and selected it this time and copied everything over. It provided a file called “Persistence” and the contentView file had a bunch of stuff already filled in (Also something called the title of the program). I have the data I need saved to the persistent data storage narrowed down to a singular array, but none of the videos I found online showed this version of xcode that supplied a “Persistence” file when using core data so I’m unsure how to use it. I will provide the contentView and Persistence file for context. The array I need saved is called mainList in contentView. ContentView: import SwiftUI import CoreData struct ContentView: View { var mainList = [RecipeList(),RecipeList(),RecipeList(),RecipeList(),RecipeList()] @Environment(.managedObjectContext) private var viewContext @FetchRequest( sortDescriptors: [NSSortDescriptor(keyPath: Item.
2
0
1.8k
May ’22
Using scrollTo(_, anchor: _) within List based upon SectionedFetchRequest
I have a Multiplatform app for iOS and macOS targets written 100% SwiftUI. I'd prefer to keep it that way, although will consider view representable options. Its a Core Data driven app, also implementing NSPersistentCloudKitContainer, I have a three column view, the first a List with style .sidebar, the second a List of items for an Entity in my Core Data model object graph, the third a detail view for the selected item in the second column List. I have begun to implement @SceneStorage to persist selected rows/cells in the lists (and sidebar), which works very well. However, if a selected row or cell is half way down the list => off screen, then the user cannot see the selection and for some reason the detail view does not show the details of the selected item, until the user manually scrolls down to the item in the list. When the selected item is revealed on screen via the manual scroll action, it is shown as selected item in the list and the detail data is only then populated. I want to be able
0
0
1.3k
May ’22
CloudKit + NSPersistentCloudKitContainer: CKError "Service Unavailable" (6/2022); "Request failed with http status code 503"
I am developing a macOS and iOS application that uses NSPersistentCloudKitContainer to sync data across devices. For about an hour, I was able to successfully save records to the CoreData container and have them sync successfully with CloudKit. After further testing, I began receiving errors similar to the following: CoreData: error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _exportFinishedWithResult:exporter:](1347): : Export failed with error: Now any device that tries to save records to CloudKit will get this error and I am unable to continue developing my iCloud sync features. Note that I am currently in Development environment with a new iCloud container, and do not yet have any users or pushed these changes to production. I have tried the following: Reinstall the application Restart all devices Logging out and back into iCloud from devices Updating my AppleID to use a single new iCloud container identifier from the developer portal as suggested in a comment here: https://developer.apple
1
0
1.4k
May ’22
Reply to Saving images & video to Core Data (with CloudKit)
Syncing large data files in CoreData<->CloudKit is particularly challenging. If you just store data in Binary Data attributes, that get converted into CKAssets, then fetching and modifying those CKRecords can take a long time, and potentially timeout, particularly if the user backgrounds the app and it gets suspended. To my knowledge, NSPersistentCloudKitContainer does use background tasks for syncing, but these aren't the same as long-lived operations, which are handled outside of the app. I've been pondering these issues for a while now, and have been working on an update to an open-source sync engine called CloudCore, with support for Cacheable Assets. Its a bit complex to establish your schema and code, but once done, large files you associate with CoreData managed objects are uploaded and downloaded using long-lived operations. The feature isn't quite ready yet, still doing some real-world testing, but you can see the progress here… https://github.com/deeje/CloudCore/pull/28 and feel free
Topic: Programming Languages SubTopic: Swift Tags:
May ’22
Sync for the first time the CloudKit data
My app backup the data to iCloud or sync with user device through the user iCloud account using NSPersistentCloudKitContainer privateDataBase. The main problem is, when user install the app I need to know if user has data in iCloud or not according this information, I let user to setup account or fetch the existing account, since it takes too long to fetch with local CoreData, I am trying to find a way to fetch directly from iCloud through CloudKit, since I am new in CloudKit, I don't know how to fetch data from CloudKit any help appreciate.
0
0
729
May ’22
Mistake about CKReference in Using Core Data With CloudKit (WWDC 2019)
The presenter says you might be wondering why we don't do this with CKReference instead. And that's because CKReference has some limitations that we don't think work well for Core Data clients. Namely that it's limited to 750 total objects. However, that isn't correct, the 750 limit is only for references that have a delete action: https://developer.apple.com/documentation/cloudkit/ckrecord/reference Important There is a hard limit to the number of references with a CKRecord.ReferenceAction.deleteSelf action that any one record can have. This limit is 750 references, and any attempt to exceed it results in an error from the server. This is why the Notes app has no issue with more than 750 note records with a reference to a folder record. I really wish NSPersistentCloudKitContainer had used CKReference and also that _CKReferenceActionValidate was made public. CKShare has limitations too, yet it used that and there was no custom sharing done like custom references were done.
0
0
851
May ’22