Search results for

NSPersistentCloudKitContainer

589 results found

Post

Replies

Boosts

Views

Activity

Reply to WidgetKit and CoreData/CloudKit
I don’t think this last comment is accurate, at least as of iOS 15. In digital lounges at WWDC Apple engineers explained it is possible for NSPersistentCloudKitContainer to sync while your app is open in the background. It seems though the work is scheduled with utility priority. In my testing it will sync if you make 4 changes - once enough updates are accumulated it’ll process them. But even then my widget is showing the changes from the 3rd update because it hasn’t yet finished updating it seems, and attempting to delay it causes the code not to execute I assume because iOS suspends the app again very soon after. So basically it may eventually sync in background, only if your app is already open in background, and it may not be reliable and your widget might not get the most up-to-date data. Maybe this can be improved by utilizing background task API, that’s what they suggested trying in the digital lounge. Do note they also said NSPersistentCloudKitContainer does not support multi-proces
Jun ’22
icloud-container-environment with NSPersistentCloudKitContainer
The com.apple.developer.icloud-container-environment provides the option to set the development or production environment to use for the iCloud containers. My app uses Core Data, and I have implemented NSPersistentCloudKitContainer. When I am not working on schema changes, I would like my local development builds to still access the production Core Data store. However, setting this entitlement to Production has not produced this result... the container is still listed as 'Staging' and I can see in the CloudKit Console that the Development container is being used. Does this entitlement only apply to direct use of CloudKit, and not to NSPersistentCloudKitContainer? If it doesn't apply to the latter, is there another way to direct NSPersistentCloudKitContainer to use the Production container? This is an iOS app though I am beginning work on a macOS version and would like to be able to do this in both environments.
1
0
2.7k
Jun ’22
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
Jun ’22
CloudKit + NSPersistentCloudKitContainer: CKError "Service Unavailable" (6/2022); "Request failed with http status code 503"
I am developing a macOS and iOS application that uses NSPersistentCloudKitContainer to sync data across devices. For about an hour, I was able to successfully save records to the CoreData container and have them sync successfully with CloudKit. After further testing, I began receiving errors similar to the following: CoreData: error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _exportFinishedWithResult:exporter:](1347): : Export failed with error: Now any device that tries to save records to CloudKit will get this error and I am unable to continue developing my iCloud sync features. Note that I am currently in Development environment with a new iCloud container, and do not yet have any users or pushed these changes to production. I have tried the following: Reinstall the application Restart all devices Logging out and back into iCloud from devices Updating my AppleID to use a single new iCloud container identifier from the developer portal as suggested in a comment here: https://developer.apple
1
0
1.4k
May ’22
Reply to Saving images & video to Core Data (with CloudKit)
Syncing large data files in CoreData<->CloudKit is particularly challenging. If you just store data in Binary Data attributes, that get converted into CKAssets, then fetching and modifying those CKRecords can take a long time, and potentially timeout, particularly if the user backgrounds the app and it gets suspended. To my knowledge, NSPersistentCloudKitContainer does use background tasks for syncing, but these aren't the same as long-lived operations, which are handled outside of the app. I've been pondering these issues for a while now, and have been working on an update to an open-source sync engine called CloudCore, with support for Cacheable Assets. Its a bit complex to establish your schema and code, but once done, large files you associate with CoreData managed objects are uploaded and downloaded using long-lived operations. The feature isn't quite ready yet, still doing some real-world testing, but you can see the progress here… https://github.com/deeje/CloudCore/pull/28 and feel free
Topic: Programming Languages SubTopic: Swift Tags:
May ’22
Reply to Different Scenarios with Core Data and CloudKit
hi, i would think your easiest solution is to use the built-in linkage between Core Data and CloudKit using NSPersistentCloudKitContainer. this takes care of all of your concerns: your data is stored locally in Core Data and mirrored to/from the cloud for you. everything works fine when offline or not signed in to iCloud. just remember that in this design, the Cloud becomes the source of truth for your data. modify data on one device; it is synced with iCloud; and then the data is synced with your other devices, where their local Code Data store is synced to match what's in the cloud. there would be no option for the user here to choose which data they want to use, as you say, the backed-up data or the new data. once your device is online and signed into iCloud, your on-device data will be synced to be a mirror of what's in the cloud. hope that helps, DMG
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’22
CoreData: preview canvas won't work with 2x entities and relationship
I've tried to create a simple CoreData entity and use the PreviewProvider to display the results. This worked fine (The first entity that got displayed was the GoalInformation). After this i've extended my entity with a relationship to another entity. This is a screenshot from the Xcode editor: More information about the entities: This is my ContentView struct ContentView: View { @Environment(.managedObjectContext) private var viewContext @FetchRequest( sortDescriptors: [NSSortDescriptor(keyPath: Goal.information!.name, ascending: true)], animation: .default) private var items: FetchedResults var body: some View { VStack { Text(count: (items.count)) } } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() .environment(.managedObjectContext, PersistenceController.preview.container.viewContext) } } The preview of the PersistenceController looks like this: static var preview: PersistenceController = { let result = PersistenceController(inMemory: true) let viewContext =
1
0
1.3k
Apr ’22
[General] -[NSAlert runModal] may not be invoked inside of transaction begin/commit pair
I receive the following error in terminal in my macOS and iOS targets that crashes a universal app written entirely in swiftUI. [General] -[NSAlert runModal] may not be invoked inside of transaction begin/commit pair, or inside of transaction commit (usually this means it was invoked inside of a view's -drawRect: method.) App structure is Sidebar Menu + Master List + Details using Core Data for persistence and Cloudkit NSPersistentCloudKitContainer for backup / mirroring. There seems to be a lot of activity prior to the crash relating to IMKInputSession CFRunLoopObserver. The crash seems to be associated with a Picker view within the detail view and whether it is First Responder at the time another item in the list is selected or a new item is added to the list (from the toolbar). Apple has suggested that... It seems that the app is presenting an alert in response to SwiftUI updating views. That use of -presentError: should be deferred outside of that immediate update (e.g. adding an observer block t
3
0
1.7k
Apr ’22
Reply to CloudKit and Serial-port Communication
I have done research on serial port communication using a macOS app a little bit ago but it seems like I will need to use a Command-line tool program. Is this correct? If I do go the Command-line tool route I will have to use cktool I believe. Will cktool allow me to use NSPersistentCloudKitContainer or similar command to allow a silent notification type fetch data system?
Mar ’22
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
Mar ’22
'Transaction' is ambiguous for type lookup in this context - SwiftUI
I'm developing a SwiftUI multi-platform, multi-user app for family budget management (not for the App Store) using CoreData and iCloud with NSPersistentCloudKitContainer. I use manual Codegen in Xcode to generate the CoreData entity classes, then add extensions for computed properties. These are in my DataModel (ViewModel), which is in an included framework. All data processing is done in the data model. All's working fine in the SwiftUI Views, except for one entity - 'Transaction', which throws a compiler error 'Transaction' is ambiguous for type lookup in this context. Some SO posts say to use the App Name as a prefix to the type, but this doesn't work. What does solve it, in this case, is to use the name of the Framework (Library) holding the type definition: import SwiftUI import OurMoneyLib // my framework holding the DataModel and CoreData entity classes struct TransactionRow: View { let appAPI = AppAPI() var transaction : OurMoneyLib.Transaction var body: some View { ...... Why this one entity
1
0
3.2k
Mar ’22
WidgetKit doesn't fetch updated data from Core Data when WidgetCenter.shared.reloadAllTimelines() gets called
The app uses Core Data + CloudKit. When the app gets launched WidgetKit file fetches correct entries from Core Data but when I add new entries to Core Data from the main app and call WidgetCenter.shared.reloadTimelines() updated entries don't get fetched and old data is displayed inside the widget. Main app and Widget target have the same App group, iCloud capability enabled for both targets. When I call WidgetCenter.shared.reloadTimelines() from the Main app Widget reloads (timer added to Widget view sets to zero) but fetch from Core Data doesn't return newly added entries. Then I restart the app and correct entries get fetched. Why doesn't it fetch correct entries when WidgetCenter.shared.reloadTimelines() gets called and only works when app is relaunched? Widget's code: import WidgetKit import SwiftUI import CoreData struct Provider: TimelineProvider { ttfunc placeholder(in context: Context) -> HabitsEntry { ttttHabitsEntry(date: Date(), habitsCount: 0) tt} ttfunc getSnapshot(in context: Context, comple
3
0
2.9k
Mar ’22
Reply to File System vs Core Data for persisting data
adding to Claude31, SwuiftUI's @FetchedResults, and the underlying NSFetchedResultsController, are IMHO a key reason to adopt CoreData: changes in the background at the model layer get signaled to the main thread view layer, which can then be dynamically updated. The other reason to use CoreData is enabling device-to-device synchronization (for a user with multiple devices, or data shared between users) via NSPersistentCloudKitContainer (or an open-source sync engine like CloudCore).
Mar ’22
Reply to NSPersistentCloudKitContainer - Import failed because applying the accumulated changes hit an unhandled exception
Please file a bug report with Apple using Feedback, if you haven't already done so. Quote my report FB9859660. I am in the same situation as you, and feel as though I'm the only one! I too don't know what to say to my users, other than Apple have a bug and they are working on it, with no timescale for resolution. People are not happy! It was working perfectly well in iOS14. Now it's not in iOS15. Instruments suggests to me that there is probably a memory leak in NSPersistentCloudKitContainer. Large spikes in Virtual Memory usage on all imports (even the small ones) but the small ones dont trigger a crash. The same (smallish) database in iOS14 uses 36MB of VM but in iOS15 uses 1.49GB for example!!
Mar ’22
Unable to handle conflict reported by NSCloudKitMirroringDelegate
I'm working on an app that uses NSPersistentCloudKitContainer to handle CloudKit sharing. Against all odds I've gotten the sharing to work, but now I'm seeing errors on startup that look very much like some kind of background loop trying to merge changes from multiple users and failing. In a more traditional CloudKit installation not backed on NSPersistentCloudKitContainer this feels like a case where I'd have to provide some code to handle the merge. In the brave new world I can't seem to find anyway to affect this Mirroring Delegate. It starts when I initialize the NSPersistentCloudKitContainer and produces the error below (as well as a long stream of similar errors). Any ideas? error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _exportFinishedWithResult:exporter:](1347): : Export failed with error: , hasProtectionInfo=true, invitationTokenStatus=Healthy, isAnonymousInvitedParticipant=false> ) === Server: ( , cached=false, publicKeyVersion=2>, hasProtectionInfo=true, in
1
0
1.1k
Mar ’22