Skip to main content
The 2024 Developer Survey results are live! See the results

Questions tagged [swiftdata]

SwiftData is a Swift-based Apple framework for managed persistence. It combines CoreData persistence technology with Swift’s modern concurrency features.

1 vote
1 answer
1k views

Delete multiple selected items in a list using SwiftData

Update: Filed feedback FB12498822 I'm exploring SwiftData before migrating some existing apps using Core Data. However, I'm not even able to implement this simple action. What I'm trying to ...
Anthony's user avatar
  • 767
1 vote
2 answers
1k views

View in SwiftUI does not get updated when model changes

I am inserting a new item into the modelContext (while on the single Deck) and the view is supposed to update automatically, but it does not. It refreshes only when I navigate back from a single Deck ...
Damian Kociszewski's user avatar
22 votes
1 answer
3k views

SwiftData - How to observe changes to the database outside of SwiftUI?

I have a simple example. I fetch all Trip objects from my database: import SwiftData @Model class Trip { var name: String } func fetch() { let container = ModelContainer(for: Trip.self) ...
SwiftedMind's user avatar
  • 4,131
1 vote
0 answers
520 views

Predicate failing with UUID's?

I have a fairly simple Categories class shown at the bottom of the post. keyValue is a UUID value, but this predicate is failing. let keyPredicate = #Predicate<Categories> { $0.uuidKey == ...
adamek's user avatar
  • 2,462
1 vote
2 answers
664 views

Preview building failed with test data

I am using the new SwiftData to persist the data into the database. For testing purposes, I have created fake data for UI preview as follows: @MainActor let modelTestContainer: ModelContainer = { ...
softshipper's user avatar
  • 33.5k
1 vote
0 answers
341 views

SwiftData: Missing argument for parameter #1 in call

When using SwiftData and defining a @Model, there may be an error Missing argument for parameter #1 in call that is rather strange. It is caused by a property initialization that does not mention the ...
Hardy's user avatar
  • 4,706
6 votes
3 answers
7k views

How to preload data into SwiftData model?

import Foundation import SwiftData @Model class Example: { let name: String let type: String init(name: String, type: String) { self.name = name self.type = type } } ...
user1659305's user avatar
5 votes
1 answer
1k views

SwiftData how to form a search predicate with a one to many model

I am working in Xcode 15 (beta) migrating to SwiftData and am having a hard time figuring out how to form a predicate in my one to many model. The desired result is to return a query that returns ...
David's user avatar
  • 297
15 votes
4 answers
9k views

SwiftData query with dynamic properties in a View

I'm trying to figure out how to make a SwiftUI view that displays data from SwiftData using a query that includes variables passed into the view. I'm guessing that I won't be able to use the @Query ...
Mike Bedar's user avatar
0 votes
0 answers
788 views

Child view behavior with SwiftData One-To-Many-Relationship

Problem XCode 15 Beta I'm testing the new Beta version of Xcode and had some problems with the @Binding behavior. I recreated the approximate view structure. I tried accessing the models array of the ...
SPR's user avatar
  • 41
3 votes
2 answers
1k views

Access Core Data ModelContainer with SwiftData

I have an app that uses CoreData and I want to migrate to SwiftData. After following the Migrate to SwiftData session, I only need to point to my old Core Data file to read the old data and convert it ...
alexkaessner's user avatar
  • 2,616
4 votes
3 answers
5k views

Can't Get Reference to SwiftData ModelContainer and ModelContext in MVVM Class

I'm trying to understand the new SwiftData framework. It's pretty easy to get it to work as long as I do everything in a SwiftUI view. I'm trying to be a good coder and separate the data from the UI ...
JohnSF's user avatar
  • 4,130
7 votes
2 answers
733 views

SwiftData: Use ObjectID URIRepresentation to load CoreData object?

I am replacing some CoreData code within my iOS App to use the new SwiftData framework. In my original code, I was saving a CoreData object URI in UserDefaults for a quick bookmark. This allowed me to ...
DookieMan's user avatar
  • 1,044
0 votes
1 answer
735 views

SwiftData crashes when using @Query with major/minor sort descriptors

Using Xcode Version 15.0 beta (15A5160n) steps to reproduce: Insert the code below into a new project Build and run First time, tap the “Setup” button to populate the SwiftData container. All of the ...
Chuck H's user avatar
  • 8,070
4 votes
2 answers
2k views

SwiftData how to delete data from an entity

I am working on migrating my code into SwiftData and can't seem to find any good answers on how to delete the data in that entity. In Swift I had this function created: class func deleteEntity(entity:...
David's user avatar
  • 297

15 30 50 per page