Search results for

NSPersistentCloudKitContainer

589 results found

Post

Replies

Boosts

Views

Activity

Persistent Storage for Previewing
In the previous version of my app, I used this pattern for previews that depended on a NSManagedObjectContext: struct ContentView_Previews: PreviewProvider { static var previews: some View { tttt let managedObjectContext = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext return ContentView().environment(.managedObjectContext, managedObjectContext) } } With the delegate gone, I've swapped to this: class PreviewData { static var persistentContainer: NSPersistentContainer = { let container = NSPersistentCloudKitContainer(name: Structure) container.loadPersistentStores(completionHandler: { _, error in if let error = error { fatalError(Unresolved error (error)) } }) return container }() static var previewContext: NSManagedObjectContext { persistentContainer.viewContext } This works for previews some of the time. For example, I have this FilteredList: import CoreData import SwiftUI protocol StructureManagedObject { static var defaultSortDescriptors: [NSSortDescriptor] { get }
3
0
1.7k
Jun ’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
Core Data + CloudKit - data record type does not appear in CloudKit Dashboard
I created a blank SwiftUI project and included Core Data and Cloud Kit. By selecting Core Data and CloudKit while creating the project, Apple already included some Core Data sample code and entities in the project, and also a Persistence.swift file that contained NSPersistentCloudKitContainer code. The sample code included a SwiftUI list in ContentView, with an Add button to add timestamp to the list when pressing. **I suppose after some basic setup to the project and created the CloudKit container, the app data will auto sync and can be viewed in CloudKit dashboard, but it didn't. ** Here is what I have setup: Created the project with Core Data and Cloud Kit Haven't touch any code from the Persistence.swift file since Apple has already set it up. Also haven't touch the app struct, content view and core data entities (left all sample code untouched) Selected Automatically Manage Signing and Development Team, with a paid developer acc. Added iCloud Capability Selected CloudKit in iCloud Capability, Cr
2
0
1.8k
Sep ’22
Ambiguity around the new CloudKit Dashboard
Ok, I'm having a tough time trying to figure out the missing pieces of how to integrate Core Data with CloudKit, given in this fantastic talk WWDC19 here. The only thing missing from the talk was a demo on the CloudKit Dashboard - which is an important thing to leave out, because it's completely changed!I've downloaded the CoreDataCloudKitDemo sample code, and have logged into iCloud on the simulator and set up a container in the dashboard with the same bundle id as the sample code app.When I run it, it sets up the schema on CloudKit Dashboard as expected. This is verified when I created a post in the app on the simulator, a record type of CD_Post is in the CloudKit Dashboard. That's fine, check.What it doesn't do though is upload the data. I'm just trying to verify if the data is in CloudKit Dashboard, yet when I do a query on CD_Post I get 0 results. I'm trying on the public database, but I've also tried on the private and shared database with the same results.On that note, I'm also confused about how to ac
3
0
1.4k
Sep ’19
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
CloudKit is not accessible from iOS extension targets
Hi! I'm using CoreData + CloudKit. It works well both on macOS and iOS, however, I can't make it work with extensions (share, action, keyboard). I get Invalid bundle ID for container error: error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _recoverFromPartialError:forStore:inMonitor:](2812): : Error recovery failed because the following fatal errors were found: { = ; } I checked everything 10x: profiles, bundle ids, entitlements, etc. I even removed all local provisioning profiles and recreated them, I also tried setting different CloudKit container, but nothing helps. I tested it on a real device. My setup: main app bundle id: com.org.App.dev keyboard bundle id: com.org.App.dev.App-Keyboard action extension bundle id: com.org.App.dev.Action-Extension CloudKit container id: iCloud.com.org.app.dev I keep the CoreData database in the app group container, but I also tried locally and it doesn't really matter. This is how I setup my CoreData: self.persistentContainer = NSPersistentCloudKitContainer
3
0
789
Jul ’24
CoreData sharing/collaboration feature is broken
On top of unstable CloudKit sync, we've got also extremely unstable sharing/collaboration functionality. I mean, it's quite impressive how easy it is to enable sharing, but this feature should not be released at this point. It feels like using software in the alpha version. Let's take NSPersistentCloudKitContainer.share(_:to:) (https://developer.apple.com/documentation/coredata/nspersistentcloudkitcontainer/3746834-share), the documentation says: Sharing fails if any of the following conditions apply: Any objects in managedObjects, or those the traversal finds, belong to > an existing share record. However, it's wrong... if you pass any object from the existing share, it will return the same share... It never fails in this case. Things are getting even weirder if you experiment a little bit with shares. So let's assume you share a couple of objects: persistentContainer.share([A, B, C, D], to: nil) Now you stop sharing those via UICloudSharingController and you want to share again but just C. So yo
1
0
669
Aug ’24
CloudKit integration seeding, conflicted objects log
Hello,I have an issue in an app which is yet unreleased.The app uses Core Data, and I recently added CloudKit integration.Whenever I start the app data get automatically downloaded by CloudKit and I get this log: <NSCloudKitMirroringDelegate: 0x600001da61b0> - Never successfully initialized and cannot execute request '<NSCloudKitMirroringImportRequest: 0x6000024c88a0> D3FB21AB-94ED-40B7-859B-6CBEE6149473' due to error: Error Domain=NSCocoaErrorDomain Code=134404 (null) UserInfo={NSDetailedErrors=( Error Domain=NSCocoaErrorDomain Code=133021 (null) UserInfo={NSExceptionOmitCallstacks=true, conflictList=(n NSConstraintConflict (0x600003f40e00) for constraint (n namen): database: 0x8143748c0004e8e1 <x-coredata://272191BB-7D10-41DD-8E4B-56F4ECE4AB9F/Ingredient/p195>, conflictedObjects: (n 0x8143748c181ce8e1 <x-coredata://272191BB-7D10-41DD-8E4B-56F4ECE4AB9F/Ingredient/p1733>n),n NSConstraintConflict (0x600003f42fc0) for constraint (n namen): database: 0x8143748c029ce8e1 <x-coredata://27
3
0
1.3k
Mar ’20
coredata entities from public configuration are not synchronized to cloudkit
In Core data public configuration, added new attribute to entities, new entities, but the changes are neither synchronized nor data is transferred to existing container schema in cloudkit. private var _publicPersistentStore: NSPersistentStore? var publicPersistentStore: NSPersistentStore { return _publicPersistentStore! } private var _privatePersistentStore: NSPersistentStore? var privatePersistentStore: NSPersistentStore { return _privatePersistentStore! } private var _sharedPersistentStore: NSPersistentStore? var sharedPersistentStore: NSPersistentStore { return _sharedPersistentStore! } static let shared = PersistenceController() static var preview: PersistenceController = { let result = PersistenceController(inMemory: true) let viewContext = result.container.viewContext do { try viewContext.save() } catch { // Replace this implementation with code to handle the error appropriately. // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping
2
0
684
Feb ’24
CD4CK confusion around the new CloudKit Dashboard
TL;DR - the data created in the CoreDataCloudKitDemo WWDC sample app can't be fetched in the CloudKit Dashboard. What is missing from the docs/WWDC talk to make this queryable in the Dashboard?---------------------------First time CloudKit integrater here, so I may be having a problem that's obvious to others but not so much to myself. I'm having a tough time trying to figure out the missing pieces of how to integrate Core Data with CloudKit, given in this fantastic talk WWDC19 here. The only thing missing from the talk was a demo on the CloudKit Dashboard - which is an important thing to leave out, because it's completely changed!I've downloaded the CoreDataCloudKitDemo sample code, and have logged into iCloud on the simulator and set up a container in the dashboard with the same bundle id as the sample code app.When I run it, it sets up the schema on CloudKit Dashboard as expected. This is verified when I created a post in the app on the simulator, a record type of CD_Post is in the CloudKit Dashboard. That
1
0
947
Sep ’19
CoreData with CloudKit on watchOS
Hello,I have managed to get CoreData with CloudKit working with the new NSPersistentCloudKitContainer on the iOS version of my app and got it to automatically sync while the app is running. However, when I went to set things up on the watchOS app, I noticed that a sync will only occur if I force close and reopen the watch app.The following scenarios workUser has both the watchOS app and iOS app runningUser makes a change to the data on the watch appThe change is reflected on the iOS appUser has only the iOS app runningUser makes a change to the data on the iOS appThe user opens the watchOS app from terminatedThe changes are reflected on the watchOS appThe following scenario does not workUser has the watchOS app running and the iOS app runningUser makes a change to the data on the iOS appNo change every makes it through to the watchOS app, even after waiting a long timeOnly if I force close the app and restart does a sync occurIn the cases were a sync is successful I see the following logs correctly:C
3
0
1.7k
Sep ’19
Implementing an iCloud on off button in SwiftUI results in crash
I've added iCloud into my SwiftUI app and everything seems to be working great, however I need to implement an on off toggle for it. After searching, I found a couple forums posts that suggested to re-create the container when icloud is toggled on off. Here's the code: lazy var persistentContainer: NSPersistentContainer = { ttreturn setupContainer() }() /* This is called when the iCloud setting is turned on and off */ func refreshCoreDataContainer() { tt/* Save changes before reloading */ tttry? self.persistentContainer.viewContext.save() tt/* Reload the container */ ttself.persistentContainer = self.setupContainer() } private func setupContainer() -> NSPersistentContainer { ttlet useCloudSync = UserSettings.shared.enableiCloudSync ttlet container: NSPersistentContainer! tt/* Use the icloud container if the user enables icloud, otherwise use the regular container */ ttif useCloudSync { ttttcontainer = NSPersistentCloudKitContainer(name: App) tt} else { ttttcontainer = NSPersistentContainer(name: A
0
0
1.1k
Nov ’20
CoreData+CloudKit Model Migration Failing
So I've been developing happily with CoreData+CloudKit for a while now, and really haven't run into any issues until this. I've migrated my model a couple of times, and it worked fine, but this was the first time I added a new entity to the model. If I run on a device (any device, iPhone, iPad, Mac via Catalyst), I get a migration error. Here's the entirety of my persistentContainer setup: public var persistentContainer: NSPersistentContainer = { let modelPath = Bundle(for: CoreDataStack.self).url(forResource: Progress, withExtension: momd)! let model = NSManagedObjectModel(contentsOf: modelPath)! let container = NSPersistentCloudKitContainer(name: Progress, managedObjectModel: model) container.loadPersistentStores(completionHandler: { (storeDescription, error) in if let error = error as NSError? { print(storeDescription) fatalError(Unresolved error (error), (error.userInfo)) } }) return container }()And here's the error I'm getting:Callstacks=true}}}CoreData: annotation: : Attempting recovery from e
10
0
5.8k
Jun ’20
Best Practices for Binary Data (“Allows External Storage”) in Core Data with CloudKit Sync
Hello Apple Team, We’re building a CloudKit-enabled Core Data app and would like clarification on the behavior and performance characteristics of Binary Data attributes with “Allows External Storage” enabled when used with NSPersistentCloudKitContainer. Initially, we tried storing image files manually on disk and only saving the metadata (file URLs, dimensions, etc.) in Core Data. While this approach reduced the size of the Core Data store, it introduced instability after app updates and broke sync between devices. We would prefer to use the official Apple-recommended method and have Core Data manage image storage and CloudKit syncing natively. Specifically, we’d appreciate guidance on the following: When a Binary Data attribute is marked as “Allows External Storage”, large image files are stored as separate files on device rather than inline in the SQLite store. How effective is this mechanism in keeping the Core Data store size small on device? Are there any recommended size thresholds or known lim
2
0
278
Oct ’25
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