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

SwiftData missing symbol on device with Xcode Beta 5
I can run my app with SwiftData just fine on the simulator but when I launch on device (on the latest Developer Beta): dyld[1800]: Symbol not found: _$s9SwiftData22RelationshipDeleteRuleO7cascadeyA2CmFWC Referenced from: /private/var/containers/Bundle/Application/FD0E19EA-A563-4B44-825B-FB42FA08F17E/MyApp.app/MyApp Expected in: <49E09F5C-ED41-3CA9-9F56-FEBA1FBE971D> /System/Library/Frameworks/SwiftData.framework/SwiftData
2
1
539
Jul ’23
Has anyone successfully used NSStagedMigrationManager?
I've been trying to build an example of NSStagedMigrationManager from some Core Data migration tests to replace a custom migration manager solution I'd constructed, without much success. The Core Data model has seven model versions. Most support lightweight migration, but two of the migrations in the middle of the sequence used NSMappingModel. In the first beta, just attempting to construct an NSStagedMigrationManager from the series of stages failed with an unrecognized selector. That no longer happens in b4, but I now get an error that "Duplicate version checksums across stages detected." If I restrict myself to just the first three versions of the model (that only require lightweight migration), I can build the migration manager. But if I attempt to use it to migrate a persistent store, it fails somewhere in NSPersistentStoreCoordinator with a nilError. The documentation is almost nonexistent for this process, and the WWDC session that introduced it isn't much more than a breezy overview. So maybe I'm holding it wrong? (And, yes: FB12339663)
5
0
1k
Jul ’23
CloudKit Stopped Syncing after adding a new Attribute
My App is in the App Store, and synced well between iOS devices with the same iCloud account. But after adding a new attribute to an entity 2 weeks ago, the CloudKit stopped syncing. I checked the Cloudkit console, and can't find the new attribute there! I don't know Why. Actually this attribute already works well in the newest version of my App downloaded form App store. Then I chose to deploy schema changes, but there are no changes to deploy! So how to deploy the new change? and how to make the iCloud syncing work again? Thanks!
2
0
659
Jul ’23
Crash when accessing relationship property of SwiftData model
I have two one-to-many models and I'm getting an unexplained crash when trying to access the relationship properties of the models. The reason for the error is as follows: Thread 1: EXC_BREAKPOINT (code=1, subcode=0x1038f4448) Xcode shows that the error occurs in the model's .getValue(for: .rows) method. This is my SwiftData model and other code: @Model class Row { var section: Section? init(section: Section? = nil) { self.section = section } init() { self.section = nil } } @Model class Section { @Relationship(.cascade, inverse: \Row.section) var rows: [Row] = [] init(rows: [Row]) { self.rows = rows } } class ViewController: UIViewController { var container: ModelContainer? override func viewDidLoad() { super.viewDidLoad() do { container = try ModelContainer(for: [Section.self, Row.self]) } catch { print(error) } let row = Row() let section = Section(rows: [row]) section.rows.append(row) var myRows = section.rows //Accessing relationship properties causes crash print("hello") //no print } } If I access the relationship property of the model, the program crashes. Such as passing to a variable. var myRows = section.rows Or just printing the relationship property of the model also crashes. print(section.rows) Xcode 15 beta 4 and 5.
1
0
511
Aug ’23
Cloudkit data merge got duplicate
Hi, developer I have face the duplicate issue while using cloudkit. I am using registration app. I use cloudkit for generate UHID also. Is cloudkit is good to generate UHID. My problem, Cloudkit automatically sync the data in background at the time user create new reg. Eg: Cloudkit had 20 data but in local it insert 11 data and is in progress at the user create new one, i fetch latest UHID and i get 11 at the time i get the duplicate. I use the deduplicate code also, but some times not helpful also if two user get reg data at the same time it get conflict.
0
0
390
Aug ’23
SwiftData AppGroups
I'm trying to use SwiftData for iOS + watchOS app but can't seem to get it to work via app groups. Both apps run fine but no changes to model are reflected in either of them. Tried running example app but it's the same thing - the app is updated but extension is not. Anyone had the same issue and knows how to solve it? Maybe some workaround? I tried multiple ModelConfiguration's with no luck and looking at debug messages in the console it seems like both apps are pointing to the same data store. I'm using Xcode 15 beta 5
1
0
480
Aug ’23
Save object to shared database
Maybe I'm going about this completely the wrong way but I've got two stores loaded in my app: private and shared. I've got zone-wide sharing enabled and I can update records that exist in the shared database (on the participant device), and see updates sync when changed by the owner. However, is it possible to save a new object specifically to the shared database as the participant? If I create a new object in my managed object context it saves it to the private database. Can provide code if needed but it's more conceptual at this stage.
1
0
684
Aug ’23
SwiftData with two Stores
Hi, has anybody managed to get two sqlite stores working? If I define the stores with a configuration for each it seems like that only the first configuration and and therefore the store is recognised. This is how I define the configuration and container: import SwiftData @main struct SwiftDataTestApp: App { var modelContainer: ModelContainer init() { let fullSchema = Schema([ SetModel.self, NewsModel.self ]) let setConfiguration = ModelConfiguration( "setconfig", schema: Schema([SetModel.self]), url: FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!.appendingPathComponent("Sets.sqlite"), readOnly: false) let newsConfiguration = ModelConfiguration( "newsconfig", schema: Schema([NewsModel.self]), url: FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first!.appendingPathComponent("News.sqlite"), readOnly: false) modelContainer = try! ModelContainer(for: fullSchema, configurations: [setConfiguration,newsConfiguration]) } var body: some Scene { WindowGroup { ContentView() } .modelContainer(modelContainer) } } ContentView is just a basic TabView with a tab for news and a tab for sets. If I run the program this way the sets tab is shown correctly but switching to News fails. If I change the order of the configurations and write the one for news first like this: modelContainer = try! ModelContainer(for: fullSchema, configurations: [newsConfiguration, setConfiguration]) then the news tab is shown correctly and switching to sets tab fails. NewsModel and SetModel only differ in the class name Import Foundation import SwiftData @Model public class NewsModel{ public var name: String init(name: String) { self.name = name } } Also the tab content differs only for referencing the respecting model and the name: import SwiftData struct NewsTab: View { @Query private var news: [NewsModel] @Environment(\.modelContext) private var modelContext var body: some View { ScrollView{ LazyVStack{ ForEach(news){actNews in Text("Hello, News \(actNews.name)") } } .onAppear { let news = NewsModel(name: "News from \(Date())") modelContext.insert(news) try! modelContext.save() } } } } The error message is "NSFetchRequest could not locate an NSEntityDescription for entity name 'NewsModel'" (and SetsModel respectively when change the order of the configuration) Do I explicitly need to tell the modelContext which configuration it should use or is this done automatically? I'm a little lost here and hope someone can help me. Best regards, Sven
5
0
2.1k
Aug ’23
SwiftData modelContainer Error
It's been frustrating to solve this error. My iOS device and Xcode are fully updated. I can easily run app on simulator, but issue happens on my iPhone. dyld[23479]: Symbol not found: _$s9SwiftData12ModelContextC6insert6objectyx_tAA010PersistentC0RzlFTj Referenced from: <6FC773BB-E68B-35A9-B334-3FFC8B951A4E> Expected in: /System/Library/Frameworks/SwiftData.framework/SwiftData
2
3
893
Aug ’23
SwiftData CloudKit integration requires that all attributes be optional, or have a default value set
After install XCode 15 beta 6: @Model class WordResult { var text = "" var translation:[String] = [] init(){ } } got this error: Variable 'self._$backingData' used before being initialized so I changed to : @Model class WordResult { var text:String var translation:[String] init(){ self.text = "" self.translation = [] } } Then got this: CloudKit integration requires that all attributes be optional, or have a default value set It seems it can not work with cloudkit now.
5
3
1.7k
Aug ’23
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
417
Aug ’23
Core Data foreign key/relationship between two tables
hi, this is a very simple concept that I can't seem to solve using relationships with core data between two tables. for instance, I have a client table with a name field that I want to link to a client details table with a clientName field and when I update/edit the client name, this still stays links to the client details record. make sense? I tried relationships but it does not link up when I edit the client name. I feel like I'm missing something very obvious here and have tried multiple scenarios but I'm not finding a solution nor am I finding any documentation on how this should work. any help/ideas is appreciated. Thank you, Pete
0
0
404
Aug ’23
visionOS and SwiftData: 'member' macro cannot be attached to property
Create a new Multiplatform App project Select SwiftData as a storage option In the main Target add Apple Vision as a Supported Destination target Select "Apple Vision Pro" as a run destination Build and run (start the active scheme) Expect: Successful build Actual: Build error: /var/folders/25/7fgb4nf92lx09_gptkqy42f80000gn/T/swift-generated-sources/@__swiftmacro_6Sherpa4Item5ModelfMm_.swift:2:13 'member' macro cannot be attached to property The code (with the macro expanded) looks like this: @Model final class Item { var timestamp: Date init(timestamp: Date) { self.timestamp = timestamp } @Transient private var _$backingData: any SwiftData.BackingData<Item> = SwiftData.DefaultBackingData(for: Item.self) // 'member' macro cannot be attached to property public var backingData: any SwiftData.BackingData<Item> { get { _$backingData } set { _$backingData = newValue } } static func schemaMetadata() -> [(String, AnyKeyPath, Any?, Any?)] { return [ ("timestamp", \Item.timestamp, nil, nil) ] } init(backingData: any SwiftData.BackingData<Item>) { self.backingData = backingData } @Transient private let _$observationRegistrar = Observation.ObservationRegistrar() // 'member' macro cannot be attached to property }
3
2
488
Aug ’23
Referencing instance method 'setValue(for:to:)' on 'Array' requires that 'Task' conform to 'PersistentModel'
I am trying to add into @Model this class: @Model class Test: Identifiable { var id: Int var tasks: [Task] = [] init(id: Int, tasks: [Task]) { self.id = id self.tasks = tasks } } while Task is a simple struct struct Task: Identifiable { var id: String var name: String init(name: String) { self.id = UUID().uuidString self.name = name } } And I am getting this 3 errors: Referencing instance method 'setValue(for:to:)' on 'Array' requires that 'Task' conform to 'PersistentModel' and Referencing instance method 'getValue(for:)' on 'Array' requires that 'Task' conform to 'PersistentModel' and Referencing instance method 'setValue(for:to:)' on 'Array' requires that 'Task' conform to 'PersistentModel' exactly for the line in the Test class: var tasks: [Task] = [] which opens hidden code as following: { init(newValue) accesses (_$backingData) { _$backingData.setValue(for: \.tasks, to: newValue) } get { _$observationRegistrar.access(self, keyPath: \.tasks) return self.getValue(for: \.tasks) } set { _$observationRegistrar.withMutation(of: self, keyPath: \.tasks) { self.setValue(for: \.tasks, to: newValue) } } } Is it not possible to have an array as part of the new @Model SwiftData approach? Is there a simple fix for it that I cannot find out?
4
1
2.1k
Aug ’23