iCloud & Data

RSS for tag

Learn how to integrate your app with iCloud and data frameworks for effective data storage

CloudKit Documentation

Post

Replies

Boosts

Views

Activity

Sharing CoreData objet with nested data
Is there a way to share CoreData data containing complex relationships easily by file? And also to create them easily after receiving the file? The application runs on a secure iPad without iCloud, so CloudKit is not an option. I'd really like to keep the file principle, so that data can be shared via Airdrop, e-mail, file transfer, etc. The ideal would be : data = myNSManagedObject.toJSON() file = createFile(data) share file receive file data = file.data.decodeJSON() myNSManagedObjectContext.add(data) All this without having to browse all the objects to create them individually Thx
0
0
287
Jan ’24
CKSyncEngine with SwiftData
I have been working on a toy app to learn CKSyncEngine. I'm using SwiftData as local storage with Cloudkit disabled, and use the CKSyncEngine to handle everything with full control. I've gotten everything to work except for one thing! Updating the UI from the SyncEngine. I have tested this outside the syncEngine and using @ModelActor and performing changes in a detached Task in the background updates the UI perfectly. However, I've made my class conforming to the engine a model-actor but it does not update the UI when I save from the actor's ctx. If I go back to a view in the navigation and return the data is updated, but not when it is modified. I'm at my wit's end and I think it must be the way CKSyncEngine updates are triggered in the background. Any suggestions to the possible root cause?
0
1
496
Jan ’24
app name in iCloud "Manage Storage" list is wrong
Hello: We have a problem and we don't know how to solve it. We have developed the following two App: app1 and app2 Both App have the function of using iCloud.The iCloud container id of app1 and app2 is the same.We use the document storage function of iCloud. We originally planned to share iCloud data in two app, so we used the same iCloud container, and we released app1 and then app2. Due to the slow progress of app2 development, the related functions of iCloud have not been added to the code yet. But we found a problem. In the storage management of "setup", iCloud, the display name of app1 is app2's name, not app1's name. This causes many of our users to delete the iCloud data of the application by mistake, resulting in losses. Now our question is: What caused the name in app1's iCloud storage management list to be displayed as the name of app2? How should it be solved?
2
1
585
Feb ’24
Unable to access CloudKit Database containers
Hello, We have a problem and we don't know how to solve it. Our application uses CloudKit databases. We can no longer access the CloudKit databases. When we connect to the CloudKit console and select CloudKit Database, we get the message "No Containers". However, the application continues to work by downloading files located on CloudKit Database. How can I modify CloudKit Database data?
0
0
518
Feb ’24
Syncing SwiftData with server API
Hello, I have a List view that populates from a REST API (listApiKeys() calls out to server). The response is decoded and stored in a swiftdata model. It looks like this: NavigationStack(path: $path) { List { ForEach(keys) { key in NavigationLink(value: key) { Text(key.name) } } } .navigationDestination(for: GtApiKey.self) { key in EditApiKeyView(apiKey: key, navigationPath: $path) } .refreshable { try? modelContext.delete(model: GtApiKey.self) await listApiKeys() } .toolbar { Button("Create Key", systemImage: "plus", action: createKey) } } .navigationTitle("test apikeys") .task { await listApiKeys() } This all works fine and SwiftData stores everything great. If I click into a single object's edit view, everything works great as well. My question is how do I sync changes to the SwiftData entry back to the server. My edit view uses a @Bindable and any changes auto-sync to SwiftData (expected). But, I can't seem to figure out where to catch those events or prevent them before I can send the PUT call to the REST API. This seems like a pretty basic pattern. But all the docs / tutorials load data then only change locally. I couldn't find one that get in sync w/ a server side API. Thanks in advance!
0
0
595
Feb ’24
SwiftData - Load the data into Apps
I am developing "Tasty Recipes" app. I want to load all data related to this app such "Recipe Category", "Recipes List", "Recipes Inscredient", "Preparation Methods" and so on. How can I load and store all data using SwiftData. User is going to use these data. They will update few things like "Favourite Recipes", "Rating". How can I do this.
2
0
555
Feb ’24
App unresponsive when calling record(for:) on NSPersistentCloudKitContainer
I'm experiencing an unresponsive UI since MacOS 14.0 and iOS 17.0 when calling record(for: ) or recordID(for:) on the instance of NSPersistentCloudKitContainer. On MacOS, the UI freeze almost always happens when calling the function. On iOS, it is necessary that the device (or simulator) does not have any network connection. I would like to ask if anyone experienced the same problem. I have posted the problem twice to Apple via the Feedback app (once for iOS and once for MacOS). No reply yet on MacOS but on iOS Apple marked it as resolved because apparently no one but me has experienced this problem. In the meantime, I have set up a minimum reproducible example app (MRE).: https://github.com/DominikButz/NotesApp-Cloud-Kit-Record-UI-Freeze- Anyone interested, please read the readme of the repository. It includes step by step instructions on how to reproduce the bug. I can't rule out I have misunderstood the usage of CoreData and CloudKit - in that case please point me in the right direction. The app I'm working on should also work offline (and on MacOS!) but it doesn't do so properly as long as this bug exists. I'm exploring switching to SwiftData (which would mean no one using macOS 13 / iOS 16 can use my app...) but I would still need to access cloud kit records even with SwiftData and I fear the bug also exists in SwiftData. Thanks
3
0
543
Feb ’24
Aggregated Data Table (Reporting Table) in CloudKit database
I need to track user actions, for example video view count. Then the data is used to get most popular videos for last 7 days, 30 days and for a year. For this purpose I have created a Downloads table with timestamp and video fields. Each time user opens the catalog, I'm running queries to get Downloads and sort the videos based on them. This is a working, but not the efficient solution. A good option is to add aggregated data table storing summary counts for the popular queries - countFor7Days, etc. This will improve query performance. But it requires a job that would update the aggregate table every day. The question is how to implement this job in CloudKit? Is there are such built-in feature, or I need a custom service running somewhere?
3
1
666
Feb ’24
SwiftData/DataUtilities.swift:1093: Fatal error: Unable to parse keypath for non-PersistentModel Type
My iOS Testflight App is crashing immediately after download/start (on all physical devices) iOS Console says: SwiftData/DataUtilities.swift:1093: Fatal error: Unable to parse keypath for non-PersistentModel Type The code is probably it is during self.modelContainer = try ModelContainer( for: Model1.self, Model2.self, Model3.self, Model4.self, configurations: ModelConfiguration(isStoredInMemoryOnly: isPreview)) modelContainer.mainContext.autosaveEnabled = true The app runs fine on physical devices in run scheme (debug or release) I have no clue how to solve this. Any ideas?
3
0
994
Feb ’24
SwiftData ModelContainer can not be created in iOS 17.4 Beta
I have an app in the app store which is working fine. Some users reported that they have app crashing when they are using iOS 17.4 beta. I could recreate the issue and it is happening when ModelContainer is crerated. This code.. do { let configuration = ModelConfiguration(for: MyTodo.self, isStoredInMemoryOnly: false) modelContainer = try ModelContainer(for: MyTodo.self, configurations: configuration) } catch { fatalError("Failed to load model container.\(error)") } is throwing this error message: Fatal error: Failed to load model container.SwiftDataError(_error: SwiftData.SwiftDataError._Error.loadIssueModelContainer)
8
0
2.6k
Feb ’24
Crash in CoreData (_PFExternalReferenceData)
I'm currently facing an interesting issue. A customer is reporting back that my app is crashing on launch for them. I can see the crash logs (using AppCenter for crash management), and the reason the app is crashing seems to be in CoreData: (Attaching text for seachability, and screenshot for readability): libsystem_platform.dylib _platform_memmove$VARIANT$Haswell CoreData -[_PFExternalReferenceData initForExternalLocation:safeguardLocation:data:protectionLevel:] CoreData -[NSSQLSavePlan _populateRow:fromObject:timestamp:inserted:shouldAddToRowCache:] CoreData -[NSSQLSavePlan _createRowsForSave] CoreData -[NSSQLSaveChangesRequestContext executePrologue] CoreData -[NSSQLCore dispatchRequest:withRetries:] CoreData -[NSSQLCore executeRequest:withContext:error:] CoreData -[NSPersistentStoreCoordinator executeRequest:withContext:error:] CoreData -[NSPersistentStoreCoordinator _routeHeavyweightBlock:] CoreData -[NSPersistentStoreCoordinator executeRequest:withContext:error:] CoreData -[NSManagedObjectContext save:] I have never seen that crash before, it's the first time it is appearing since CoreData has been incorporated into the app (in 2016 or so). Any hints on what could possibly be happening? I am unable to provoke the crash on my end, thus debugging is quite interesting.
1
0
386
Feb ’24
SwiftData Predicate with "format:"
Hi, if you have an array of object IDs, with CoreData you can fetch all of the objects for those IDs at once with the right predicate. It would look something like this: let objectIDs: [NSManagedObjectID] = [id1,id2,id3,id4] let predicate = NSPredicate(format: "self in %@", objectIDs) Can something similar be created with a SwiftData predicate? For now I fetch all ids one by one and as you might guess, performance wise this is not great.
0
0
388
Feb ’24
Swift Data Fail to previewivrelationship
Hi! I was trying to develop a todo list app. There are two models: import Foundation import SwiftData @Model class Item { var id: UUID var title: String var detail: String @Relationship(deleteRule: .cascade, inverse: \SubItem.item) var subitems: [SubItem] var isCompleted: Bool var timestamp: Date init(id: UUID = UUID(), title: String = "", detail: String = "", subitems: [SubItem] = [], isCompleted: Bool = false, timestamp: Date = .now) { self.id = id self.title = title self.detail = detail self.subitems = subitems self.isCompleted = isCompleted self.timestamp = timestamp } } @Model class SubItem { var id: UUID var title: String var isCompleted: Bool var item: Item init(id: UUID = UUID(), title: String = "", isCompleted: Bool = false, item: Item) { self.id = id self.title = title self.isCompleted = isCompleted self.item = item } } In a component view, I was trying to preload some sample data in the preview: struct ItemRowView: View { @Bindable var item: Item //...... } #Preview { let schema = Schema([ Item.self, SubItem.self ]) let modelConfiguration = ModelConfiguration(schema: schema, isStoredInMemoryOnly: true) let container = try! ModelContainer(for: schema, configurations: [modelConfiguration]) let context = container.mainContext var item: Item = Item(title: "Item title 1", detail: "") var subitem1 = SubItem(title: "subitem 4", item: item) var subitem2 = SubItem(title: "subitem 2", item: item) context.insert(item) context.insert(subitem1) context.insert(subitem2) return ItemRowView(item: item) .modelContainer(container) .padding() } However, item.subitems is always empty in this view. What's wrong?
0
0
249
Feb ’24
Advice for AppSupport to AppGroup migration before publishing
Hi all In pursuit of adopting widgets in my application, I have transitioned from AppSupport to AppGroup as storage location for Core Data. I have done a migration process/flow that goes as follows and which have been tested multiple times although I have yet to publish the update: Check if migration has taken place or not 1a. if yes continue to app 1b. If no continue flow Begin migration process 2a. Backup original store in AppSupport 2b. Migrate store to AppGroup 2c. Migrate userdefaults to AppGroup 2d. Update userdefaults with true for both hasMigratedToAppGroup and hasMigratedUserDefaultsToAppGroup Is there any tips or stuff to look for that hasn’t been taken in to account? How have you done it previously, and what would be recommended? Also, is there some specific tests to run/over many times get a baseline of how many is succeeding or failing? Thanks in advance.
4
0
735
Feb ’24