Search results for

NSPersistentCloudKitContainer

589 results found

Post

Replies

Boosts

Views

Activity

NSPersistentCloudKitContainer/Core Data design approach
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
0
0
846
May ’23
How to sync data between iOS and OSX apps with CloudKit?
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
0
0
425
Jan ’24
Can I access CloudKit's metadata fields with NSPersistentCloudKitContainer?
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.
0
0
633
Aug ’23
Receiving NSPersistentStoreRemoteChange notification when app is closed
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
0
0
715
Oct ’23
100% CPU, Energy Efficiency NSPersistentCloudKitContainer / Best Practices?
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
0
0
943
Nov ’21
Child records not showing in the Shared Database when sharing the Parent record in CloudKit
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.
0
0
529
Jul ’20
How to extend NSPersistentCloudKitContainer to upgrade generated CKRecords
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.
0
0
511
Jul ’20
Data Collection
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
0
0
358
Nov ’21
Share RecordZones or ParentRecords in CoreData-CloudKit Share
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
0
0
763
Dec ’21
CoreData+CloudKit integration issue
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
0
0
1.1k
Aug ’21
Question about NSPersistentCloudKitContainer and sharing
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
0
0
902
Jun ’21
NSPersistentCloudKitContainer and App Extensions
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
0
0
945
Jun ’21
Sync iCloud with different targets
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
0
0
645
Jun ’21
Migration of a Custom Core Data CloudKit Sync to NSPersistentCloudKitContainer
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
0
0
697
Dec ’20
Initialize NSPersistentCloudKitContainer with iOS 14 and Public DB
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
0
0
736
Mar ’21