Search results for

NSPersistentCloudKitContainer

589 results found

Post

Replies

Boosts

Views

Activity

Reply to PersistenceController and CloudKit
struct PersistenceController { static let shared = PersistenceController() let container: NSPersistentCloudKitContainer init() { container = NSPersistentCloudKitContainer(name: MJ) guard let fileContainer = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: group.com.Jad.MJ)?.appendingPathComponent(MJ.sqlite) else { fatalError(Shared file container could not be created.) } let storeDescription = NSPersistentStoreDescription(url: fileContainer) storeDescription.setOption(true as NSNumber, forKey: NSPersistentHistoryTrackingKey) storeDescription.setOption(true as NSNumber, forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey) storeDescription.cloudKitContainerOptions = NSPersistentCloudKitContainerOptions(containerIdentifier: YOUR containerIdentifier) container.persistentStoreDescriptions = [storeDescription] container.loadPersistentStores(completionHandler: { (storeDescription, error) in if let error = error as NSError? { fatalError(Unresolved error (error), (er
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Dec ’21
PersistenceController and CloudKit
Hello I am making a To-Do list app where I use CoreData and CloudKit, the problem is that when I added this line of code container.persistentStoreDescriptions = [NSPersistentStoreDescription(url: fileContainer.appendingPathComponent(MJ.sqlite))] to the PersistenceController, iCloud syncing stopped working. (I need that line of code in order to permit to extensions to access the CoreData database) Any idea to solve the problem? This is all the PersistenceController code struct PersistenceController { static let shared = PersistenceController() let container: NSPersistentCloudKitContainer init(inMemory: Bool = false) { container = NSPersistentCloudKitContainer(name: MJ) guard let fileContainer = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: group.name) else { fatalError(Shared file container could not be created.) } container.persistentStoreDescriptions = [NSPersistentStoreDescription(url: fileContainer.appendingPathComponent(MJ.sqlite))] container.loadPersistentStore
3
0
2.5k
Dec ’21
WidgetKit + CoreData with CloudKit
Hi, I am developing an app with CoreData + CloudKit and wanted my Widget to fetch data from CloudKit to display. Everything is working on iOS / watchOS, but on WidgetKit the result from my fetch is always empty. I already configured the CloudKit capability on the Widget extension, then I am creating a new NSPersistentCloudKitContainer the and on public func timeline(with context: Context, completion: @escaping (Timeline<Entry>) -> ()) { I am trying to let cardsFetch = NSFetchRequest<Card>(entityName: Card) do { let cards = try persistentContainer.viewContext.fetch(cardsFetch) the result is always 0 and the same fetch on iOS returns the data. Is this supposed to work?
8
0
3.3k
Dec ’21
@SectionedFetchRequest with hierarchical data structure (maybe OutlineGroup?)
I am working on a couple of Multiplatform apps that use a very similar 3 column layout - sidebar menu (or tabs for sizeClassHorizontal == .compact), with a master list under each menu option and detail view based upon master list selection. The apps use Core Data framework and NSPersistentCloudKitContainer for backup and syncing across a user's devices. The apps use Codegen = Class Definition and I write extensions for each entity to prepare convenience methods, properties, comply with generic protocol conformance. I am learning how to retrofit sectioned fetch requests into each master List. Generally this is straightforward and I'm really happy with the result. However, one particular master list is based upon an hierarchical data structure and I have investigated using the children: parameter in List to successfully create an hierarchical list. So to be clear, the following code is based upon @FetchRequest var gardens: FetchedResults (not a sectioned fetch request) and works well... extension Garde
3
0
2.2k
Nov ’21
Reply to Why does CloudKit data field (bytes) take up more (~10 times) iCloud storage than asset field?
@DD21 Did you end up finding a solution? I'm using NSPersistentCloudKitContainer to have CloudKit + Core Data and I'm observing the same issue. I have saved ~6000K items in Core Data, which some of them have images. The local size for the sum of the images is around 76 MB, but if you check it on iPhone > Settings > Apple ID > iCloud > Manage Storage, it shows up as ~760 MB, which is the 10x increase in size that you reported a year ago. This seems to be a bug on the whatever's in charge of calculating the size for iCloud assets, because when I delete my app from my device and let it download all the information stored on iCloud again, it finishes the download extremely fast (I'm assuming because it's only downloading 76MB). If it were downloading 760MB, it would take much longer knowing my network connection speed. Now, if this bug actually affects user's iCloud quota (which it seems that it does), it is a large scale issue that might be impacting millions of users. Users might have much
Topic: App & System Services SubTopic: Core OS Tags:
Nov ’21
NSPersistentCloudKitContainer not syncing existing data
I'm running into trouble setting up sync using NSPersistentCloudKitContainer on an existing app. The app doesn't seem to sync data that was added to Core Data prior the app's iOS 13 update. For instance:1. I install an existing, pre-iOS 13, version of the app and create several records that are stored in Core Data.2. Over that existing install, I install the updated version that uses NSPersistentCloudKitContainer and create some additional new records.3. I install the same new version on a second device.Results: Records created in step 1 don't appear on the second device, but records created in step 2 do.Is there a step I'm missing in order to get existing data to sync? I'm wondering if this has something to do with the persistent history token, but I'm unsure how to tell NSPersistentCloudKitContainer it should start over on first launch.
22
0
15k
Nov ’21
Reply to NSFileProtection confusion
Here's a working snippet: container = NSPersistentCloudKitContainer(name: YourDataModelName) container.persistentStoreDescriptions.first!.setOption(FileProtectionType.complete as NSObject, forKey: NSPersistentStoreFileProtectionKey) container.loadPersistentStores(completionHandler: { (storeDescription, error) in ...
Topic: Privacy & Security SubTopic: General Tags:
Nov ’21
Coredata and CloudKit not synchronized
1/ Signing & capabilities background mode - > remote notification cloud -> cloudkit @ container created 2/ coredata ->used with cloudkit & all attributes are optionals 3/ appDelegate NSPersistentCloudKitContainer viewContext.automaticallyMergesChangesFromParent = true AND it's not working on my two devices (iPhone & iPad) under iOs 15.0.2 What did I forget?
2
0
861
Oct ’21
NSPersistentCloudKitContainer with public database doesn't work and is poorly documented
So I tried the public database feature of NSPersistentCloudKitContainer last year but never really got anywhere so I thought i'd try it again this year. However I've still had basically no luck and I figured now might be a good time to try and document the issues I have had. The documentation for this at https://developer.apple.com/documentation/coredata/mirroring_a_core_data_store_with_cloudkit/creating_a_core_data_model_for_cloudkit mentions shouldInitializeSchema which from what I can gather was removed in a beta version a long ** time ago. It appears to now be a method on the container - container.initializeCloudKitSchema(). Ya'll should update this documentation. initializeCloudKitSchema does not work if you have options.databaseScope = .public on the NSPersistentCloudKitContainerOptions. You get a bunch of errors saying No authToken received for asset Turning off the public scope and then calling initializeCloudKitSchema gets you the Record types you need created in the CloudKit console, then r
9
0
6.2k
Oct ’21
NSPersistentCloudKitContainer: how to un-share objects?
I’m working on an app that uses the new sharing support in NSPersistentCloudKitContainer. I do not see a way to tell Core Data that an object, or set of objects, is no longer shared. For example, if I create a set of objects and then call share(_:to:completion:), the objects are shared properly and moved to a new, custom CKRecordZone, as expected. Now, if the user stops sharing an object using UICloudSharingController, the CKShare that Core Data created is properly deleted from CloudKit, but the objects are still in the custom zone, and Core Data still has the original CKShare associated with those objects. So, when I call fetchShares(matching:), I still get the CKShare, but of course, that is no longer valid. Forcing Core Data to fetch CloudKit changes by either moving the app to background and then foreground, or by stopping the app and relaunching does not cause Core Data to notice the change to the share. Does anyone know how to tell Core Data that these objects are no longer shared? Note, I’ve t
3
0
1.6k
Oct ’21
Reply to NSPersistentCloudkitContainer Memory Leak -> Crash? (iOS 15 beta 4 & 5)
This is all very confusing to me... ...and it's quite possible that this 'bug' is something I'm doing wrong when ingesting data from a backup file, despite it all appearing to save to Core Data just fine. But why now though? Why has it been working just fine for almost 2 years without modification? Backup Restore Process The backup file that my users create is a serialised dictionary file, which includes encoded data for images (if present). When I restore it, I use a private context to ingest it on a background thread, with a progress bar being updated on the main thread. As I do not want partially imported data to be incorporated into the user's Core Data store I only save the context at the end of the import when successful. This has been working flawlessly for the past 2 years with NSPersistentCloudKitContainer, with the data syncing after the import finishes and is saved to Core Data... but was it only working by accident all this time!? Should I not be using the private context to save imported
Sep ’21
Reply to NSPersistentCloudkitContainer Memory Leak -> Crash? (iOS 15 beta 4 & 5)
Sorry, Apple... this is still broken in iOS 15.1 (beta 2) The CPU & RAM usage is still excessive and no syncing occurs at all. I've replied to my TSI in the hope I can get someone to look into this as a matter of urgency. I now have users running iOS 15 who are no longer seeing their data syncing via iCloud, resulting in a terrible user experience, using my app downloaded from the App Store which has been unchanged since iOS 14. Whatever Apple did in iOS 15 beta 4 to NSPersistentCloudKitContainer, they broke it badly. Maybe users who don't have complex databases aren't seeing this problem, but the whole point of NSPersistentCloudKitContainer is to sync a Core Data store with complex relationships (and besides, it works just fine on iOS 13 & iOS 14!). My testing setup Monterey (beta 8) Xcode 13 (13A233) non-beta Testing on iPhone 13 Pro with iOS 15.1 (beta 2) Preparation Deleted iCloud data for my app Deleted my app from the device (App Store download) Rebooted device Reset the iCloud
Sep ’21
Reply to NSPersistentCloudKitContainer Bug
I wanted to follow up on this statement in my first post for any other readers: the root NSManagedObject's record is not being updated with the relationship linkage to the shared record. I figured out later that this is because there are 2 different ways to do shares: you share Records or Zones. The new share functionality in NSPersistentCloudKitContainer appears to be creating full Zone shares unlike the code documented on CKShare. When the Zone share is made there are no relationships created on the records in the zone because they are all made available to the Participants. In terms of the bug with local ckshare being updated, that is still an issue. I haven't tested the suggestion by Fat Xu yet and in the meantime I had to query CloudKit directly (not thru NSPersistentCloudKitContainer) for the most recent ckshare records.
Sep ’21
Reply to databaseScope lead to dyld: Library not loaded on xcode13-beta with simulator 14.5
Not an answer I’m afraid, but perhaps a related problem. They’ve definitely changed something deep at the OS level which is even affecting the CloudKit syncing of apps built with the iOS 14 SDK many months ago (ie. my app!) if run on an iOS 15 device, let alone apps built with the iOS 15 SDK! This failure of syncing started to occur when iOS 15 beta 4 was released - prior to this it was all working normally, as it did in iOS 13 & iOS 14. From beta 4 the entire structure of the console log outputs for NSPersistentCloudKitContainer changed, so something fundamental changed with CloudKit at this time. In my case, it seems it has trouble syncing Core Data relationships and NSPersistentCloudKitMirrorringDelegate gets stuck in a loop causing CPU & RAM consumption to rise uncontrollably, with the OS killing the app shortly afterwards. No syncing occurs. My Core Data structure has not changed since iOS 14 and my app synced (and still does) just fine on iOS 14 devices. Other than a reply from a ‘Frame
Sep ’21