I'm using NSPersistentCloudKitContainer together with a private and public database. I have a public database with articles. Users should be able to like an article but I'm wondering what would be the best design approach to achieve this. The users can also add articles that they find online which are then automatically liked for the user adding it (and uploaded to the public database) Question 1 I want you to be able to see how many people have liked an article, so I think there will perhaps be an array on the article with the userId who liked it and then you just do a count on it? Or do you think there is a better way? Question 2 I am thinking about how the liked article should be saved for the user, either put that article in their private database, but then that article will be disconnected from the public article. Or I can filter out among the public articles that contain the user's userId (however, I'm a little unsure how it works in practice as the public database is polled every 30 minutes wi
Search results for
NSPersistentCloudKitContainer
589 results found
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
We have an iOS App developed in SwiftUI that saves data to CloudKit using NSPersistentCloudKitContainer. If I modify any of this data, the changes are synchronized on other iOS devices without problem. We also have an OSX App with StoryBoard using NSPersistentCloudKitContainer to share the same data with iOS devices. Changes made on OSX are updated immediately on iOS devices. But if any data is modified in iOS, it is not updated in the OSX application. Simply by doing Command-Tab twice the OSX app displays the new data. It appears that CloudKit Push Notifications are not causing the OSX application to detect that there are changes to the data and that it needs to be updated. In both cases an NSFetchedResultsController is created and a delegate is placed. The iOS one is called but the OSX one is not. The only difference in the code is that in the iOS app with SwiftUI it is done: var body: some Scene { WindowGroup { InitialTab() .environment(.managedObjectContext, DataManager.shared.viewContex
I've got a simple Core Data Entity that is synchronized with CloudKit via NSPersistentCloudKitContainer. I can read my local fields, but how can I read fields like Created & Modified from CloudKit? Do I have to add them to my Core Data model and populate them myself? P.S. In his fantastic WWDC talk Using Core Data with CloudKit, at around 21:40, Nick Gillet talks about how Core Data entities in the CloudKit store are prefixed with CD_ to separate the things that it manages from the ones CloudKit implements. Then he says: You wouldn't believe how many people add modify date to their CKRecord. Like it's something redundant.
I use NSPersistentCloudKitContainer to fetch/sync data across multiple devices with the same iCloud account. /// ... container = NSPersistentCloudKitContainer(name: containerName) let description = container.persistentStoreDescriptions.first description?.setOption( true as NSNumber, forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey) description?.setOption( true as NSNumber, forKey: NSPersistentHistoryTrackingKey) let viewContext = container.viewContext viewContext.automaticallyMergesChangesFromParent = true viewContext.mergePolicy = NSMergePolicy.mergeByPropertyObjectTrump NotificationCenter.default.addObserver( forName: .NSPersistentStoreRemoteChange, object: container.persistentStoreCoordinator, queue: .main ) { _ in Task { @MainActor [weak self] in // fetch new data and update widgets with it // ... viewContext.fetch ... // WidgetCenter.shared.reloadAllTimelines() } } } /// ... Everything works fine when my app in the foreground. How can I achieve the same when my app is clos
Hi, I recently added iCloud sync capability to my app via NSPersistentCloudKitContainer. It does push data to the cloud, in other words seems to be working fine. However, I noticed a strong increase in battery drain and when I debug (release and debug build configs) I can see that a NSManagedObjectContext thread that is definitely not mine has 100% CPU load basically all the time. (I waited a few minutes, yes minutes, for it to finish while not using the app at all and it does not stop.) Component utilization shows that most the energy impact is CPU and overhead is very low (goes to 0 quickly). There is no network activity visible, so this seems to be some kind of background processing. Also, memory is very, very low (~ 35 MB). I am wondering if I am doing something wrong here or if there is a better practice. Some info about how my app works: It downloads things from the web and generates a lot of entities while doing so. It frequently saves changes (incremental changes in entities, there are lots o
I've set up a Core Data mirroring to CloudKit using NSPersistentCloudKitContainer. My simplified data structure consists of List and Item. List have one-to-many relationship items with many Items, Item has parentList property. When I am getting CKRecord associated with List NSManagedObject and sharing it, I expect all child Items to be shared too. I know, I can set parentRecord property for each CKRecord associated with the List childRecord.setParent(parentRecord) But I believe there is some smart way to avoid doing that manually, because everything is mirroring automatically and it looks not nice to start handling each single property manually to only set parentRecord. Is there any way to do that for NSManagedObjects? Because my custom relationship does not mean for CloudKit that the List is parent for the Item.
Hi, I am developing sharing feature with already working mirroring and need to set parentRecord to child items. I want to extend NSPersistentCloudKitContainer (or any it's component used for mirroring) in some way to get access to CKRecords it is creating before container will push records to the server. Goal — I want to set CKRecord.parent right before CKModifyRecordsOperation fires somewhere in NSPersistentCloudKitContainer. Reason — NSPersistentCloudKitContainer do not handle parent records by itself.
Hi everyone, I am very new to SwiftUi and am not sure about data collection to disclose. Does using the sign in with Apple feature and Core Data with CloudKit count as Data Collection? (if it does what would it come under) I use @AppStorage for the sign in and not the UserDeafult feature. For CloudKit I only use the inbuilt NSPersistentCloudKitContainer container and for saving the generic: viewContext.automaticallyMergesChangesFromParent = true viewContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy Thank you
Hello everyone, in the App I'm building I'd like to share an entire list of items (records) by just sharing the list itself (parent record or RecordZone). Meanwhile, I'd like to continue using the NSPersistentCloudKitContainer and therefore CoreData sync. Is it possible, with the new features Apple introduced (Sharing RecordZone and Sharing in Cloud & Local Storage), to do what I described, and combine both functions. Thank you, Carlos Steiner
Topic:
App & System Services
SubTopic:
iCloud & Data
Tags:
Cloud and Local Storage
UI Frameworks
wwdc21-10015
Hello. I'm trying to setup CoreData+CloudKit integration. But I receive following errors right after NSPersistentCloudKitContainer configuration. CoreData: error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _performSetupRequest:]_block_invoke(939): : Failed to set up CloudKit integration for store: (URL: file:///var/mobile/Containers/Data/Application/18992BCF-7F0C-4271-B106-947B8F52A723/Library/Application%20Support/App.sqlite) Error Domain=NSCocoaErrorDomain Code=134060 A Core Data error occurred. UserInfo={NSLocalizedFailureReason=The mirroring delegate could not initialize because it's store was removed from the coordinator.} Here is the code of persistent container setup: self.persistentContainer = NSPersistentCloudKitContainer(name: containerName) let localStorage = NSPersistentStoreDescription(url: storageURL) let localStorageOptions = NSPersistentCloudKitContainerOptions(containerIdentifier: iCloud.com.myapp) localStorageOptions.databaseScope = .private localStorage.cloudKitCont
Hopefully everyone's recovered from WWDC2021 last week! I've been digging through as much of the new documentation as I can about the NSPersistentCloudKitContainer and sharing over the last couple of days (since I can't get my code working in the XC 13 Beta... looks like a couple of bugs, I think...), and have a question. It appears that this uses Sharing by Record Zone rather than Sharing by Record, which is fine, but... How does this work when you are sharing entities between multiple users? for example... My Db contains a hierarchy of entities under a single root node, and there are multiple such entities (at the moment without overlap between the sub-entities, but I feel like that's just around the corner). Lets call them Entities A, B, and C. Now: Entity A I want to share with Joe. Entity B I want to share with Joe and Sally. Entity C I want to share with Sally and Simon. So, for Entity A I presume that it (and it's sub entities) wind up being represented in a shared record zone (SRZ) of it's ow
Can the behavior of NSPersistentCloudKitContainer be described in App Extensions? I have seen Forum entries that describe its behavior in Widgets - it will save data locally, but will not sync that data until the app is opened. This is a pretty major downsides for any apps that use SiriKit Extensions to allow for quick, simple data entry -- not syncing the data until the app is opened (which could be days later) would be a deal breaker. I hope this can be clearly described, and improved (if my understanding is correct) - I've filed a feedback to document this as well: FB9170155
Hello Is there a way to share data stored in CloudKit and CoreData between iOS and watchOS in SwiftUI? I am using the same CoreData file both, and I am using the same PersistenceController file both, and I am using the same CloudKit container for both. I tried adding the App Groups capability to all the targets, but it is not working. (I already enabled iCloud capability, Push notification capability and background Modes capability for both iOS and WatchOS) PersistenceController: struct PersistenceController { static let shared = PersistenceController() static var preview: PersistenceController = { let result = PersistenceController(inMemory: true) let viewContext = result.container.viewContext do { try viewContext.save() } catch { let nsError = error as NSError fatalError(Unresolved error (nsError), (nsError.userInfo)) } return result }() let container: NSPersistentCloudKitContainer init(inMemory: Bool = false) { container = NSPersistentCloudKitContainer(name: Test7) if inMemory { container
Hi I have an app that runs on iOS and MacOS (actually they are separate apps) and Core Data from a NSPersistentContainer, is synced with iCloud using a custom solution utilising pre-NSPersistentCloudKitContainer CloudKit methods. I would like to migrate that solution to NSPersistentCloudKitContainer but am having trouble figuring out how to do it and whether it's even possible. In particular, as I cannot guarantee that all devices would migrate at the same time, there would need to be a period where both synchronisation methods are active. Moreover, they would need to be active on one device, which would need to act as some sort of translator between the two methods. Then, it would be quite hard to determine when to stop using and delete old records from the cloud as that would have to be done from the last device to migrate. And that would be quite hard to determine from the app. Finally, as each device has its own Core Data objectIDs all managed objects would end up being duplicated in iCl
I'm struggling to initialize my schema. I keep getting the error : Error Domain=NSCocoaErrorDomain Code=134060 A Core Data error occurred. UserInfo={NSLocalizedFailureReason=Couldn't initialize CloudKit schema because no stores in the coordinator are configured to use CloudKit Without the initialize it does sometimes create the record's schema. But it feels like its all half working. I have Cloudkit on and Used with Cloudkit is checked under the default configuration in my xcdatamodeld file. Here is my setup code.. _persistentContainer = [[NSPersistentCloudKitContainer alloc] initWithName:@Eco-nomy]; // Add options and make this container PUBLIC. NSPersistentStoreDescription *description = _persistentContainer.persistentStoreDescriptions.firstObject; [description setOption:[NSNumber numberWithBool:YES] forKey:NSPersistentHistoryTrackingKey]; [description setOption:[NSNumber numberWithBool:YES] forKey:NSPersistentStoreRemoteChangeNotificationPostOptionKey]; description.cloudKitContainerOptions.databas