Swift Data is a data modeling framework from Apple for use in apps running on their operating systems, including iOS, macOS, and others. It's closely related to Core Data but is used in different, more Swift-friendly ways.
Questions tagged [swift-data]
92 questions
0
votes
1 answer
SwiftData search bar and predicate
I'm trying to create a view using the SwiftData framework with a search bar where the user can type a registration of an airplane and dynamically update the list. But first I'm not sure if I'm doing it correctly (I can't find too many examples…

Damiano Miazzi
- 1,514
- 1
- 16
- 38
0
votes
1 answer
Error trying to use SwiftData property based on an enum with an associated value
I'm trying to setup a SwiftData model with a property whose type is an enum with an associated value. The code works if the enum has no associated value.
Here's a simple model that demonstrates the issue:
@Model
final class Something {
var name:…

HangarRash
- 7,314
- 5
- 5
- 32
0
votes
0 answers
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 accomplish is to let the user choose multiple items from…

Anthony
- 747
- 1
- 8
- 23
0
votes
0 answers
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 { $0.uuidKey == keyValue }
When I use it in a fetch request I get the very…

adamek
- 2,324
- 3
- 24
- 38
0
votes
2 answers
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 = {
do {
let container = try ModelContainer(
…

softshipper
- 32,463
- 51
- 192
- 400
0
votes
0 answers
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 type, e.g.:
public var dateSpec: DateSpec =…

Hardy
- 4,344
- 3
- 17
- 27
0
votes
0 answers
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 Model1 in the second view. Im using the textfield…

Social Processing
- 39
- 5
0
votes
2 answers
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 but have been unable to get connections to the…

JohnSF
- 3,736
- 3
- 36
- 72
0
votes
1 answer
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 Attribute objects will be shown together sorted…

Chuck H
- 7,434
- 4
- 31
- 34
0
votes
2 answers
Update data in SwiftData
I am trying to update data in SwiftData. The documentation, however, is literally just:
func update(expressions: [String : NSExpression],
model: any PersistentModel.Type,
where predicate: NSPredicate? = nil) throws -> Bool
As a new…

PaytonDEV
- 63
- 1
- 6
-1
votes
0 answers
SwiftData way of child context
When creating a new object in CoreData it is possible to use child contexts to create the object then edit it and then delete the context if the process of creation is aborted.
How could this be achieved in SwiftData. Is there a equivalent of child…

sheldor
- 115
- 12
-1
votes
0 answers
How to handle conflicts when items are re-ordered from 2 offline devices (with a custom order field)?
Since Core Data doesn't support ordered one to many relationships when using CloudKit, I am thinking of adding a order: Int field to the entity like here to be able to implement ForEach {}.onMove.
Let's say a user currently has 3 items with orders…

BPDev
- 397
- 1
- 9
-1
votes
0 answers
SwiftData fetching multiple model types in the same query
I am trying to build a list that will display multiple @Models. Let's just call them A and B.
Looking at both @Query and FetchDescriptor they only seem to operate on a single type. I want something like @Query. Is that possible with…

i-konov
- 842
- 1
- 7
- 19
-1
votes
0 answers
SwiftData for each alphabet letter pick first 10 items
I don't know how to approach this issue, so I'm looking for some suggestions:
I have an airports list database with over 75K airports on it, and it is very very slow to open it when I use on my view@Query() var airports: [Airport]
So I understand I…

Damiano Miazzi
- 1,514
- 1
- 16
- 38
-1
votes
0 answers
Search in swiftData very slow how to fast the search
here is a simple project using a swift data where I saved over 75000 airports.
I'm trying to find the best and faster way to search on this db, right now the search works but it is very very slow and the UI frozen while searching.
How can I optimize…

Damiano Miazzi
- 1,514
- 1
- 16
- 38