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

API for new "Keep Downloaded" feature in iCloud Drive?
It looks like in iOS 18, there is a new option in Files to "Keep Downloaded". I.e., mark a file to be downloaded and never evicted. Is there an API that would allow us to provide this feature in our app? Our app stores files in a ubiquitous container and displays them in a custom UI (not a UIDocumentBrowserViewController). We've had a longstanding request from users that they be able to mark a file as always available locally, so that they can make sure they have access to it even if they go offline. We've done a hacky, best-effort implementation of this, but there is no truly reliable way to achieve this through the existing APIs.
1
0
120
1w
Occasional crash on `context.save()`
Recently, I noticed many crashes reported daily for context.save() in my code. I tried to resolve the issue by refactoring some of the code. My key change is to use context.performAndWait to fetch Core Data objects instead of passing them around. I refactored the code to pass NSManagedObjectID around instead of NSManagedObject itself because NSManagedObjectID is thread-safe. However, even after the refactor, the issue is still. The crash log is attached as below. I'm confused that it doesn't crash on all devices so I have no clue to find the pattern of the crashes. I also enabled -com.apple.CoreData.ConcurrencyDebug 1 on my local dev box, but seems the error cannot be caught. The new code (after I refactored) still causes the crash: private func update(movements: [InferredMovement], from visitOutObjectId: NSManagedObjectID, to visitInObjectId: NSManagedObjectID?) { let context = PersistenceController.shared.container.viewContext context.performAndWait { guard let visitOut = try? context.existingObject(with: visitOutObjectId) as? Visit else { return } var visitIn: Visit? if let visitInObjectId { visitIn = try? context.existingObject(with: visitInObjectId) as? Visit } visitOut.movementsOut.forEach { context.delete($0) } visitIn?.movementsIn.forEach { context.delete($0) } for inferred in movements { let movement = Movement(context: context) movement.type = inferred.type movement.interval = inferred.interval movement.visitFrom_ = visitOut movement.visitTo_ = visitIn } visitOut.objectWillChange.send() context.saveIfNeeded() } } Note, saveIfNeeded() is an extension function implemented as: extension NSManagedObjectContext { /// Only performs a save if there are changes to commit. @discardableResult public func saveIfNeeded() -> Error? { guard hasChanges else { return nil } do { try save() return nil } catch { defaultLogger.error("Core Data Error: Failed to save context") return error } } } Crash context
1
0
100
1w
iCloud Synchronization doesn’t work
I’m trying to sync data from the AppData on one device to another device with the same iCloud. It uploads the data to the CloudKit but it doesn’t write the data it fetches from the cloud into the AppData storage. It should store a timestamp, a few integers, and two lists of integers. The lists are both optional and store numbers. They can have 0 up to 50 numbers in them. This is the part where it should fetch the records and store them in the AppData let container = CKContainer(identifier: "iCloud.com.calchunt") let privateDatabase = container.privateCloudDatabase let dispatchGroup = DispatchGroup() var errors: [Error] = [] // Leere Liste zum Speichern neuer Spielsitzungen aus der Cloud var newGameSessions: [AppModule.GameSession] = [] for gameSession in gameSessions { let recordIDString = gameSession.id.uuidString // UUID zu String umwandeln let recordID = CKRecord.ID(recordName: recordIDString) dispatchGroup.enter() privateDatabase.fetch(withRecordID: recordID) { (existingRecord, error) in defer { dispatchGroup.leave() } if let error = error { // Fehler beim Abrufen des Records print("Fehler beim Abrufen des Records aus CloudKit: \(error.localizedDescription)") errors.append(error) } else if let existingRecord = existingRecord { // Record existiert in der Cloud print("Record mit ID \(existingRecord.recordID.recordName) existiert in CloudKit") // à berprüfen, ob der Record bereits im AppModule vorhanden ist if let _ = gameSessions.firstIndex(where: { $0.id == gameSession.id }) { // Record existiert bereits im AppModule, überspringe das Speichern print("Record mit ID \(existingRecord.recordID.recordName) existiert bereits im AppModule, überspringe das Speichern") } else { // Record existiert nicht im AppModule, füge ihn zur Liste der neuen Spielsitzungen hinzu let newGameSession = AppModule.GameSession( id: gameSession.id, losungszahl: gameSession.losungszahl, elapsedTime: gameSession.elapsedTime, currentDate: gameSession.currentDate, skipped: gameSession.skipped, skipped2: gameSession.skipped2, level: gameSession.level ) newGameSessions.append(newGameSession) print("Record mit ID \(existingRecord.recordID.recordName) wird zum AppModule hinzugefügt") } } else { // Record existiert nicht in der Cloud print("Record mit ID \(recordID.recordName) existiert nicht in CloudKit") } } } dispatchGroup.notify(queue: .main) { if !errors.isEmpty { for error in errors { print("Fehler beim Abrufen der Daten aus CloudKit: \(error.localizedDescription)") } } else { // Füge neue Spielsitzungen zum AppModule hinzu gameSessions.append(contentsOf: newGameSessions) // Speichere die aktualisierten Daten im AppStorage do { let encoder = JSONEncoder() let gameSessionsData = try encoder.encode(gameSessions) GameSessions = gameSessionsData print("Daten erfolgreich aus CloudKit geladen und im AppStorage gespeichert") } catch { print("Fehler beim Codieren und Speichern der Daten im AppStorage: \(error.localizedDescription)") } } } }
1
0
104
1w
CloudKit Request - CKAsset size limit and public database storage per active user
Hello, I had a WWDC Lab with two CloudKit engineers who asked me to file a "Feedback Request" for critical information regarding CloudKit. I've filed the FB and have also decided to post a forum post to increase my chances of having these critical questions answered. If allowed, I will also post responses to my FB here. CKAssets I would like to know how large assets attached to a CKAsset can get before being rejected by the system. If the figure differs for private and public databases, please also let me know. CloudKit pricing information There used to be pricing information available on the website, but there's basically no information now. This makes it hard to calibrate user upload limits for my app in order to avoid overage fees. I'm not looking to game the system, (something this strange opaqueness is likely meant to prevent); I'm just looking to avoid a situation where competitors and vandals abuse my the content upload system so I get smacked by large bills out of nowhere. A rough figure of how many GB of data each active user adds to my app's CloudKit public database would suffice. While we're at it, if I have two apps that share a public database (if that's possible), do the active user counts of both contribute to the public database's free threshold?
0
0
118
1w
SwiftData Custom Datastore Docs and Implementation
I have watched the following WWDC 2024 sessions: What’s new in SwiftData Create a custom data store with SwiftData Platform State of the Union Now, I have an application that exposes a GraphQL API endpoint that's using PostgreSQL Server 16.3 database. Next, this API returns JSON to the client application (i.e. SwiftUI app). Furthermore, I have checked the current documentation and the above videos appear to be the best reference at this time. My proposed architecture looks like the following: SwiftUI <--> SwiftData <--> PostgreStoreConfiguration && PostgreStore TBD <--> GraphQL API <--> PostgreSQL Thus, I have the following questions: Are there plans to add common out-of-the-box data store implementations for PostgreSQL, Cassandra, Redis, and so on? Will it be possible to implement data stores built to use gRPC, GraphQL, REST, and others to name a few? Will there be more documentation on the actual creation of a custom data store because the current documentation provides a slim API reference? I look forward to your feedback regarding the SwiftData custom data stores.
1
0
214
1w
CloudKit in TestFlight: No sync between devices 😭
I have read and tried all the possible solutions available online, but still didn't get a result. My multi-platform iOS/macOS app uses private databases in iCloud with Core Data. All works as expected when I build the app from Xcode to my multiple devices: data is being synced. But when I upload the app to TestFlight, data is not being synced. This is what I have already tried: In CloudKit Dashboard, I reset the schema and deployed schema changes from the development to production. In Xcode project settings, in Targets, under Frameworks, Libraries... I added the CloudKit.framework, set as "do not embed". In Xcode project settings, under Signing & Capabilities, all the CloudKit, Background fetch and Remote notifications checkboxes are enabled for both Debug and Release. They all point to the same correct iCloud container. In Xcode project settings, under Build Settings, Code Signing Entitlements for both Debug and Release point to the same entitlements file. In .entitlements file, CloudKit container identifier points to the correct container. iCloud Services set to CloudKit. In .entitlements file, APS Environment for both iOS and macOS is set as "production". In Core Data .xcdatamodeld file, under Configurations, I have a Default option, and it is being set to "Used with CloudKit." Each time I upload new version to the TestFlight, I delete all the previous versions from all my devices, so development and production containers are not mixed up in any way. I understand that I may be missing something. But after researching all the resources available online, I didn't find anything else to configure or to add in this setup. I want to point out again that data is not being synced only in TestFlight, and thus, possibly, after release. Whenever I build app directly to the device from Xcode, all works as expected. I hope someone can help me.
2
0
124
1w
Setting .fetchBatchSize causes entire collection to be immediately traversed
Using an @FetchRequest in my SwiftUI-redesigned app, I was looking to improve performance of my search and filtering on a List that has potentially a large amount of data. One of the things I was asking about was how to load some data initially and then fetch additional objects as the user scrolls. In a WWDC lab today, while viewing my code the Apple engineer noted I had set a .fetchLimit on my FetchRequest, and suggested that I should be setting a .fetchBatchSize. It sounded like that was designed to do exactly what I wanted. However, having attempted this, I can see from the console output that when I set a .fetchBatchSize of 50 and go to the view, it immediately loops through the entire collection of thousands of objects, attempting to load them into memory, and as some contain images this eventually crashes with an out of memory error. This data is presented in a List. Originally, inside that list there was a ForEach inside that list but the same problem was seen when I removed the ForEach and used: List(entries) { entry in if let entryData = viewModel.entryData(for: entry) { TimelineEntryView(entryData: entryData) } } Can you advise on what might be going on here? I recall that in the previous iteration of my app, in UIKit and using an NSFetchedResultsController I had the exact same symptom: setting a fetch batch size immediately traversed the whole collection in the datastore, leading to terrible performance rather than the hoped-for good performance. So I did not set a batch size then either. Am I holding this wrong? Is there something that might be triggering this?
3
0
176
1w
Using Core Data with the Swift 6 language mode
I'm starting to work on updating my code for Swift 6. I have a number of pieces of code that look like this: private func updateModel() async throws { try await context.perform { [weak self] in // do some work } } After turning on strict concurrency checking, I get warnings on blocks like that saying "Sending 'self.context' risks causing data races; this is an error in the Swift 6 language mode." What's the best way for me to update this Core Data code to work with Swift 6?
3
1
285
1w
SwiftData SchemaMigrationPlan and VersionedSchema not Sendable?
I've just tried to update a project that uses SwiftData to Swift 6 using Xcode 16 beta 1, and it's not working due to missing Sendable conformance on a couple of types (MigrationStage and Schema.Version): struct LocationsMigrationPlan: SchemaMigrationPlan { static let schemas: [VersionedSchema.Type] = [LocationsVersionedSchema.self] static let stages: [MigrationStage] = [] } struct LocationsVersionedSchema: VersionedSchema { static let models: [any PersistentModel.Type] = [ Location.self ] static let versionIdentifier = Schema.Version(1, 0, 0) } This code results in the following errors: error: static property 'stages' is not concurrency-safe because non-'Sendable' type '[MigrationStage]' may have shared mutable state static let stages: [MigrationStage] = [] ^ error: static property 'versionIdentifier' is not concurrency-safe because non-'Sendable' type 'Schema.Version' may have shared mutable state static let versionIdentifier = Schema.Version(1, 0, 0) ^ Am I missing something, or is this a bug in the current seed? I've filed this as FB13862584.
1
2
177
1w
Access SwiftData in Widgets
How do I access the SwiftData ModelContainer of my app inside the widget extension? Following the guide to add a Widget Extension I’ve added the necessary target to my project and enabled App Groups. I’ve seen that the Backyard Birds example code offers an example how to build this, but it encapsulates the SwiftData handling in a separate app package. Therefore the example simply points to the app package. Though, in my case I don’t host my SwiftData in an external app package, but simply inside the regular app target. So, my question is how and at which point in code do I need to access the ModelContainer?
1
1
185
1w
SwiftData Remote Database Updates
I just saw the new SwiftData updates, including the DataStore API. I’m wondering if, in the case of a shared remote datastore, it is possible to enable updates to the model context from the datastore without the model context explicitly requesting them (e.g., through database listeners). If I’m not mistaken, when you use CloudKit with SwiftData, this happens, right?
1
0
138
1w
SwiftData ModelContext Fetch Crashing
I'm currently using Xcode 16 Beta (16A5171c) and I'm getting a crash whenever I attempt to fetch using my ModelContext in my SwiftUI video using the environment I'm getting a crash specifically on iOS 18 simulators. I've opened up a feedback FB13831520 but it's worth noting that I can run the code I'll explain in detail below on iOS 17+ simulator and devices just fine. I'm getting the following crash: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'The specified URI is not a valid Core Data URI: x-coredata:///MyApp/XXXXX-XXXXX-XXXX-XXXX-XXXXXXXXXXXX' It's almost as if on iOS18 SwiftData is unable to find the file on the simulator to perform CRUD operations. All I'm doing in my project is simply fetching data using the modelContext. func contains(_ model: MyModel, in context: ModelContext) -> Bool { let objId = palette.persistentModelID let fetchDesc = FetchDescriptor<MyModel>(predicate: #Predicate { $0.persistentModelID == objId }) let itemCount = try? context.fetchCount(fetchDesc) return itemCount != 0 }
3
4
229
1w
Using Cloud Storage With SwiftData Custom Data Store
The following videos from WWDC24 say that we can use cloud storage for our SwiftData stores. Video references below: What's new in SwiftData Create a custom data store with SwiftData When watching the videos it shows examples of how we can read and write to a JSON file as a store, rather than using the built in store that comes with SwiftData. But there are mentions that we can use cloud storage like a backend i.e. a database hosted on a server. The only thing that I'm struggling to figure out and it would be great if we had code samples for this is how to achieve using cloud storage as a store since looking at the current implementations of: DataStoreConfiguration DataStore The required functions we need to implement look synchronous rather than asynchronous so how would or could we handle fetching asynchronous data from cloud storage. So how would we handle this? Also it would be great if someone could clarify how or if there is a way to send notifications for changes to your store between different devices similar to CloudKit? Are there there any plans to provide more documentation & sample code for the questions I've asked above? Feedback FB13857743
1
3
190
1w
SwiftData UndoManager leaks?
In any SwiftData project with undo enabled, I noticed that repeatedly undoing and redoing a change will cause memory to continuously climb. The larger the change, the more memory is consumed. This is surprising to me. I confirmed this on iOS and macOS using Xcode 15.4 and 16 beta. To reproduce, simply add undo/redo functionality to any project and repeatedly undo/redo a change. Memory consumption will climb continuously and will not get released. In Paul Hudson's SwiftData tutorials, he has an entire section about the numerous tricks required to get SwiftData relationships to work correctly. Does anyone know if SwiftData also requires tricks to get the UndoManager to work correctly?
1
0
92
1w
CKSyncEngine questions
I've been building an app with CKSyncEngine based off the documentation and sample code on GitHub. So far it's been working great, but I still have a number of questions I couldn't find the answer to I'd like to know before going into production. Here's a list in no particular order: When sending changes, are you expected to always send the entire record or just the fields that changed? It's not clear there would even be a way to know the fields that changed since when we have to populate the CKRecord from our local record, we only know the id. Likewise, when we get a record that changed on the server, do we always get a complete record even if only a single field changed? Related to that, if a record has asset(s), is the complete asset also returned on every server change even if we already have a copy locally and it hasn't been modified? If a record does have an asset, is the asset guaranteed to be downloaded and available at the asset.fileURL location by the time CKSyncEngine calls the delegate? If not, is there a way to know it's still downloading and when it will be available? Is there a way to lazy load assets to avoid unnecessary data fetching? If there is a failure during sync, for example if I fail to save just one record out of many, how do I recover from that? Is there a way to retry? Related, is there a way to verify we're completely in sync with the server? Is there any way to resync besides deleting the state serialization data and doing a complete sync again? Can I use CKSyncEngine from the main app and the app extensions if they share a database and state serialization. For example, when adding an image from the share extension. Any caveats to that? Sorry for all the questions, but I want to make sure this is as efficient and reliable as possible. I'm going to request a Lab as well, but it's the lab request form isn't working at the moment so I figured I'd post here in case it's easier to answer async. Thanks! – Zach
1
0
130
1w
Bricked com.apple.homekit.config CloudKit container
How did the issue (probably) occur? The issue appeared in January 2024 after setting up a new Apple TV 4K (tvOS 16.X and updated to latest tvOS after setup) or a new Apple Watch Ultra 2 (watchOS 10.X and updated after setup). Both devices were set up using my personal iCloud and both were set up to use HomeKit. I suspect the issue is related to the creation of a new Home that was subsequently shared to a family member (see below). How did I notice the issue? From the week that followed, I noticed that my iPhone 15 Pro Max tends to get really hot in standby and that the battery drops significantly in the space of a couple standby hours. (Worst case I’ve experienced is about ~80% drop in 4 hours standby) Apple Watch also has huge drops in battery life. Again, to give some perspective: I wear my AW for sleep tracking, sometimes AW will drop ~5% throughout the night, sometimes ~60% (and turn off if it was charged below 60%, making me lose my sleep tracking). My iPad Pro occasionally loses ~30-50% charge over night in standby. I went to the Battery section of the Settings app on my iPhone and iPad and could notice that about 50-75% of the time (over 24h that is), Home Accessories is running in the background. I could not confirm this on Apple Watch as the battery section of Settings does not show per app usage, however clear drops in battery percentage are noticeable from the graph. What's the issue? Seeing the issue arise on three of my four portable Apple devices, I decided to go check on my MacBook Pro M1 Max in Activity Monitor if the same behaviour was to be seen. I quickly realised that the Home Daemon (homed) is permanently running in background at (unusual) high usage. It is the top entry in CPU usage and Uptime. Going into the Console app I can see that the homed daemon on macOS is throwing 3x-5x batches of the same 5 error messages each second. The errors are the following: In the same Console app, connecting to my iPhone and my iPad, I can see the exact same errors occurring at approximately the same rate. What is the issue in technical terms? My CloudKit HomeKit config (com.apple.homekit.config) container is bricked and returns an internal server error The homed/cloudd daemons do not have a backoff policy and retry fetching the CloudKit database instantly on failure. This leads to an infinite loop of network requests going out and draining my battery on all devices massively. How did I try to solve the issue? All these measures were unsuccessful: Restarting all devices All devices are on the latest version Deleting the Home app where possible Turning off Home, Keychain and iCloud Drive in iCloud settings Signing out of iCloud and signing in again Using the HomeKit Reset mobileconfig profile where possible (http://appldnld.apple.com/iOSProfiles/HomeKitReset.mobileconfig) Use the previously mentioned reset profile in combination with a HomeKit Architecture downgrade (http://appldnld.apple.com/iOSProfiles/KeepLegacyHome.mobileconfig) On macOS, delete ~/Library/HomeKit Sending sysdiags using the Feedback Assistant (FB13529370, still open) Manually revoking all (pending and accepted) home invitations and deleting all homes from the Home app Removing all Apple TVs and HomePods from my iCloud account Reseting and repairing Apple Watch Disabled Advanced Data Protection on iCloud Logging out of all my devices’ iCloud, use the reset profile, wait 20min, login to iCloud, the issue reappears in the console (while no other devices are logged in) Changing Apple ID password and choose to log out all devices, log in again into a single device, use the reset profile, wait 20min, and the issue reappears in the console To be absolutely sure it is an iCloud issue and not a local misconfiguration (that could be solved by resetting all my devices), I took an older iPhone 12 Pro and set it up as a new device with no apps/account/data, just a blank installation of iOS. As one would expect, the issue is not present and the Console app does not show any errors. As soon as I log into my iCloud account, the Home daemon homed throws the same 5 errors over and over and the battery draining issue magically appears. This confirms my theory that it is indeed an iCloud issue on the server-side and not a client-side issue. Reseting my devices would not help fix the issue as demonstrated by a blank iOS installation on a separate iPhone 12 Pro getting the same error just by logging into my iCloud account. I’ve had an Apple Support case for over five months, it has been (unsuccessfully) escalated twice to engineering. While many basic troubleshooting steps have been taken, nothing helped. Also, while the Apple Support agent is really trying their best to help me, they understand the symptoms of the problem but not the root cause which I tried explaining multiple times. Essentially we’re sticking to the Apple Support instructions they have, and doing basic diagnostics and battery troubleshooting even though I technically understand and can explain the issue to a CloudKit engineer. We even proceeded to do a fresh install of macOS on a separate volume and took diagnostics before and after login in with my Apple ID. They were able to confirm that there is indeed a massive battery drain issue related to my account. The case is still open but is currently leading nowhere, I'm just told to keep my devices updated... How Apple can fix the issue: Investigating the internal server error and fixing the record(s) or the CoreData entity that is throwing the problem Implementing a client-side backoff policy for internal server errors coming from iCloud. Quite trivially by reseting my com.apple.homekit.config container Also worth mentioning: I don’t use a VPN or any Proxy I’m fine with losing all my HomeKit-related data on my iCloud account. At this point I just want the issue to disappear and to have useable battery life on all my devices. I’m giving my consent to the immediate and irrevocable deletion of all my past and present HomeKit-related data.
2
0
238
1w
Best way to share large CoreData model with extensions?
I have a large model. Not just large in complexity but literally there are gigabytes in the average user db. I want to enable saving data to this model from app extensions. However, I do not want to duplicate code or model setup. Is it recommended that I migrate to using a shared group model? How do you migrate existing stores to using shared containers? Or are there better ways to do it? For example, should I create a brand new store that uses a shared container? What are best practices?
1
0
126
1w
Crash running app in iOS18
Hi, I updated my iPad to iOS18 beta 1, and it seems to crash my app immediately, even though it's the App Store release version that's running fine on iOS17. The crash report points to some issue in NSManagedObjectContext performBlockAndWait: Thread 2 name: Dispatch queue: NSManagedObjectContext 0x303498000: CJCloudKitItemsUploaderQueue Thread 2 Crashed: 0 libsystem_kernel.dylib 0x1f1930254 __pthread_kill + 8 1 libsystem_pthread.dylib 0x2285fcef8 pthread_kill + 268 2 libsystem_c.dylib 0x1a9a76ad8 abort + 128 3 CJournal 0x105428818 0x104e28000 + 6293528 4 CJournal 0x1054261f4 0x104e28000 + 6283764 5 CoreFoundation 0x1a1c40a3c __handleUncaughtException + 660 6 libobjc.A.dylib 0x19eec8210 _objc_terminate() + 132 7 CJournal 0x1053f5ad0 0x104e28000 + 6085328 8 libc++abi.dylib 0x22852087c std::__terminate(void (*)()) + 16 9 libc++abi.dylib 0x228520820 std::terminate() + 108 10 libdispatch.dylib 0x1a99bd174 _dispatch_client_callout + 40 11 libdispatch.dylib 0x1a99cc7b8 _dispatch_lane_barrier_sync_invoke_and_complete + 56 12 CoreData 0x1a9c94a6c -[NSManagedObjectContext performBlockAndWait:] + 264 13 ContactsJournalDataKit 0x10643fb50 -[CJCloudKitModifyRecordsOperation createUnderlyingCKModifyRecordsOperationWithProcessList:withLimit:] + 408 14 ContactsJournalDataKit 0x10643f544 -[CJCloudKitModifyRecordsOperation main] + 848 15 Foundation 0x1a071e2e0 __NSOPERATION_IS_INVOKING_MAIN__ + 16 16 Foundation 0x1a071c530 -[NSOperation start] + 648 17 Foundation 0x1a07947a0 __NSOPERATIONQUEUE_IS_STARTING_AN_OPERATION__ + 16 18 Foundation 0x1a07943ec __NSOQSchedule_f + 172 19 libdispatch.dylib 0x1a99cc350 _dispatch_block_async_invoke2 + 148 20 libdispatch.dylib 0x1a99bd160 _dispatch_client_callout + 20 21 libdispatch.dylib 0x1a99c0610 _dispatch_continuation_pop + 596 22 libdispatch.dylib 0x1a99bfc40 _dispatch_async_redirect_invoke + 580 23 libdispatch.dylib 0x1a99cedf4 _dispatch_root_queue_drain + 392 24 libdispatch.dylib 0x1a99cf5f8 _dispatch_worker_thread2 + 156 25 libsystem_pthread.dylib 0x2285f9c40 _pthread_wqthread + 228 26 libsystem_pthread.dylib 0x2285f6488 start_wqthread + 8 Can anyone shed some light on this? I haven't rebuilt the app with Xcode 16 yet, just wanted to run the App Store version and see if it's compatible without doing anything.
1
0
513
1w
SwiftData context disregards unique attribute
I have a simple model with a unique field. @Model class M { @Attribute(.unique) var value: String var date: Date var answer: Int init(value: String, date: Date = .now, answer: Int = 0) { self.value = value self.date = date self.answer = answer } } I am creating new objects with let x = M(value: "x") modelContext.insert(x) The value field has a unique constraint, and I am observing these differences in iOS 18 beta (Xcode 16.0 beta) from iOS 17.5 (Xcode 15.4): Multiple objects with the same value field appear in the list. If explicit modelContext.save() is called, list is not updated with latest values. Is this something I need to adjust to, or beta issues? Full source code: https://github.com/paiv/swiftdata-insert-unique-1
2
0
128
1w