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
NSPersistentCloudKitContainer - mirror sync
My app uses a mirrored CoreData Store with NSPersistentCloudkitContainer. The user has the option to turn cloudKit sync on or off by device. The app responds by setting the description?.cloudKitContainerOptions = nil - but keeps historyTracking on by setting description?.setOption(true as NSNumber,forKey: NSPersistentHistoryTrackingKey) The app is working fine this way with multiple devices and if the user re-enables sync on a particular device that was either disabled or offline everything syncs just fine on all devices. I now want to prune History transactions and I intend to clear the history older than say 7 days only when I receive a NSPersistentStoreRemoteChangeNotificationPostOptionKey observation on transactions that are outside the app. Does a device that was either offline or had sync disabled as per above then re-enabled or come back online upload its local changes first then download changes from the store? I am concerned that if is not this way I will potentially have to keep all History
0
0
710
Dec ’21
What is the most suitable back-end integration for SwiftUI simple data synchronisation with other users?
Hi, I am designing a simple task manager for a household in SwiftUI. I would like the app to synchronise the content data across the devices of the various users part of the household. To me, this seems like a simple enough process potentially. Which approach is best suitable with the SwiftUI framework? The data model of the app is very simple at the moment; essentially a collection of tasks that each feature a title, description and assignment to a user. Running the app locally, without synchronisation implemented yet, allows me to make use of the SwiftUI's framework declarative programming and elegant design. I realise that to implement synchronisation with other users' devices unavoidably means I need to implement code and adapt existing code. For years, I have browsed articles and tutorials on data sharing in iOS apps. Options I have explored are Core Data, CloudKit, manual API fetching from server and third-party options like Realm. The underlying, unnamed issue seems to be that SwiftUI is still young an
0
0
1.9k
Feb ’21
Customize behavior of NSPersistentCloudKitContainer
I'm working on a SwiftUI app generating data using a standard CoreData data model and sync it with iCloud using NSPersistentCloudKitContainer. In this data model one parent is referencing on many children (e.g. > 2000 of children A and B). Each child A is also referencing onto one child B and vice versa: Parent ----> Child A; Parent ----> Child B; Child A <---> Child B The problem I am facing is, depending on the last time an CloudKit sync has been performed, the sync process takes hours to complete (where in the mean time the app might be sent to the background by the system or by the user and the sync is stopped). Is there a way to efficiently sync these larger datasets? Additionally I would like to pause the iCloud sync for specific occasions e.g. when performing continuous tasks using Background Modes and the app would be killed due to CPU pressure of iCloud sync. Is there a way to customize the syncing behavior of NSPersistentCloudKitContainer like e.g. CKOperation or by
0
0
882
Jun ’21
Accept CKShare with SwiftUI App lifecycle
In iOS 15, macOS 12, tvOS 15 and watchOS 8 we can finally share NSManagedObjects using NSPersistentCloudKitContainer 🎉 I've been playing around with it and I've managed to share an object from one Apple ID to another. But I'm unable to accept the invite. 😰 If I understand the docs correctly I'm supposed to call func acceptShareInvitations(…) with CKShare.Metadata representing the invite. This metadata should be forwarded to my app using either AppDelegate or SceneDelegate. The problem is that I'm using the SwiftUI App-protocol. I tried setting up an UIApplicationDelegateAdaptor with this code: ivar added @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate AppDelegate implemented class AppDelegate: NSObject, UIApplicationDelegate { func application(_ application: UIApplication, userDidAcceptCloudKitShareWith cloudKitShareMetadata: CKShare.Metadata) { assertionFailure() } } The assertionFailure is never called, so my guess is that the SceneDelegate is being called instead. So, how do I im
0
0
876
Jun ’21
Possible to override background push limits during development?
The video discusses limits to background pushes. I'm unable to finish developing my app that uses NSPersistentCloudKitContainer on iOS 14 because I believe background push notifications are being limited by the system so I am unable to test how the app behaves when it is suspended and a background push arrives. In fact I cannot get any background pushes to arrive at all, however pushes do arrive when the app is running in the foreground. Is there perhaps a development entitlement or launch param to override all limits so I can finish my app? And if not, can this feature be added please?
0
0
1.1k
Sep ’20
Core Data: Using local and iCloud
Hi everyone, I'm trying to use in my app core data as persistent storage. In this app it is supposed to have some entities of core data local but also some other synced through iCloud. In the xcdatamodeld, I create two configs that belongs to each type offline(local) and the online(iCloud) but I'm getting a strange error where it says that it can't use the same container name. I don't understand if for each entity I want to be synced on iCloud I need a different container. Also, I do not understand because if I use only iCloud syncing without using any configuration, I can store different entities. Also, if each entity has a 1:1 relationship with the container, why is impossible to delete it, it doesn't make sense. Here is the code I'm using persistentContainer = NSPersistentCloudKitContainer(name: name, managedObjectModel: model) var defaultDirectoryURL: URL var descriptors = [NSPersistentStoreDescription]() for capability in self.dbCapabilities { if capability.cloudEnable { defaultDirectoryURL = NS
0
0
478
Oct ’20
Outdated CKRecord on NSPersistentCloudKitContainer.record(for:)
Hi, I am trying to fetch CKShare for NSManagedObject. Firstly I get CKRecord for it using NSPersistentCloudKitContainer's record(for:) method. And getting situation when: First time record(for:) gives correct CKRecord I successfully create CKShare, see it in online Dashboard Next time record(for:) gives old CKRecord which don't have share yet, it's outdated! I swipe down notification Notification Center or minimise the app (go to home screen), and when go back, database is being immediately updated and record(for:) returns correct CKRecord with existing share now. I can get correct CKRecord if I use only recordID from CKRecord that I get from record(for:), and fetch updated CKRecord using fetch(withRecordID:completionHandler:). But it increase awaiting time twice because I need to get response for correct CKRecord and then fetch CKShare for it. If no share for CKRecord, I could get that nil immediately but now I have to fetch correct updated CKRecord. So, anyone know how to keep local database update
0
0
464
Jul ’20
Transformable attribute in Core Data not export/sync with iCloud
I am using NSPersistentCloudKitContainer. All data sync in iCloud. And when uninstalled the app, its sync correctly. However, it's required to encrypt sensitive data. I made my password attribute Transformable. Thus work fine locally. However when I delete the app. Install again. All other attributes(String, Int) sync correctly but transformable attribute does not export/synced.Here is my Modelhttps://i.stack.imgur.com/emA4m.pngpublic class EmployeeEntity: NSManagedObject { @NSManaged public var password: NSObject? @NSManaged public var firstName: String? @NSManaged public var lastName: String? @NSManaged public var idNumber: String? @NSManaged public var modifiedDate: Date? @NSManaged public var password: String? @NSManaged public var title: String? static var entityName: String { return EmployeeEntity }}extension EmployeeEntity { static func getListItemFetchRequest() -> NSFetchRequest<EmployeeEntity>{ let request = EmployeeEntity.fetchRequest() as! NSFetchRequest<EmployeeEntity> requ
0
0
601
Apr ’20
Cannot see records in the iCloud Production environment
I'm attempting to use Core Data + CloudKit to persist user's data with the NSPersistentCloudKitContainer class. I'm able to see created records in the Development environment but records won't show in the Production environment. With just this brief description, what could be the issue? Notes I have deployed the schema to the Production environment. I'm using the same device and iCloud account for both environments My Apple ID is the same for my personal and dev account. I'm attempting to add records to Production via a TestFlight build The iCloud toggle for the app is ON. What are some initial thoughts as to why there is a sync issue?
0
0
507
Oct ’21
On iOS 15.2, how do I load a cloudKit public container with user not logged in to iCloud
I am using the following to initialize my PersistenCloudKitContainer with the goal of loading a shared poblic cloudKit database: container = NSPersistentCloudKitContainer(name: FaceExplorer) guard let description = container.persistentStoreDescriptions.first else { print(Can't set description) fatalError(Error) } //ios 14 bug fix https://developer.apple.com/forums/thread/682925 description.cloudKitContainerOptions?.setValue(1, forKey: databaseScope) // normal / ios 15 version description.cloudKitContainerOptions?.databaseScope = .public //seems to work & Load on iOS14.5 description.cloudKitContainerOptions?.setValue(iCloud.com.myDomain.myContainerID, forKey: containerIdentifier) container.loadPersistentStores(completionHandler: { (storeDescription, error) in ... This all works great on iOS14 and also loads on iOS15.0 - 15.2 with users logged into iCloud with the iCloud drive option checked. However, when the iCloud drive option is not checked on iOS15 only, the container will not load. Please hel
0
0
589
Jan ’22