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
2
votes
0 answers
Sharing SwiftData with iCloud users
has anyone figured out how to use swiftdata in SwiftUI with CloudKit to share data among other users and set permissions? Thank you!
I checked apple’s documentation along with the internet in general. I’m not sure it’s even supported…

Adam Collin Mitchell
- 21
- 1
2
votes
0 answers
How can I share SwiftData @Model between widget and app?
I have an App Group shared between my app and its widgets.
I have SwiftData's @Model, updated from the widget intent's perform() method and displayed on the app and the widget.
@MainActor
func perform() async throws -> some IntentResult {
let…

Sergio
- 1,610
- 14
- 28
2
votes
1 answer
How to resolve compiler error creating a SwiftData #Predicate?
I have been trying so many ways to resolve this issue. I am trying to fetch SwiftData records with a predicate. but everything I try results in a pair of errors:
initializer 'init(_:)' requires that 'Item' conform to 'Encodable'
initializer…

HangarRash
- 7,314
- 5
- 5
- 32
2
votes
1 answer
SwiftData compiler error on enum property with default value
I've narrowed down this issue to a simple model class with one property with a enum type. If I attempt to give the property a default value, the code won't compile any more:
enum SomeEnum: Hashable, Codable {
case one
case…

HangarRash
- 7,314
- 5
- 5
- 32
2
votes
1 answer
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 to the new SwiftData format.
My question is how…

alexkaessner
- 1,966
- 1
- 14
- 39
2
votes
0 answers
How to configure a relationship as a Set in a PersistentModel?
The new SwiftData framework runs successfully when using an Array but produces a fatal error when using a Set in a @Relationship. Why?
import Foundation
import SwiftData
@Model
final class Item {
var timestamp: Date
@Relationship(inverse:…

parapote
- 433
- 2
- 8
2
votes
1 answer
How to use a background context with SwiftData? Looking for a CoreData automaticallyMergesChangesFromParent equivalent
I'm messing around with refactoring my model layer with SwiftData. I've got my model working and the container set up and working and now I'd like to start using a background context for CRUD operations.
Here's how I'm setting up my…

Brian M
- 3,812
- 2
- 11
- 31
2
votes
2 answers
Type 'CounterModel' does not conform to protocol 'PersistentModel` - SwiftData
I am trying to make a sample app which uses SwiftData to keep track of sports goals. I have a struct: Team which has values id (UUID), name (string), score (int), and editing (bool). I have a SwiftData model class which contains the values id…

PaytonDEV
- 63
- 1
- 6
2
votes
2 answers
How to filter object from array using Swift Macros in SwiftData and SwiftUI
I have planned to create a mini project using iOS 17 Beta in Xcode 15 Beta.
So, I created a new project using SwiftData and SwiftUI.
import SwiftUI
import SwiftData
struct HomeScreen: View {
@Environment(\.modelContext) private var…

Kathiresan Murugan
- 2,783
- 3
- 23
- 44
1
vote
0 answers
SwiftData access relationship property crash
I just want to create a temporary Playlist. When I access songs of playlist, it crashed.
There are two model as below,
@Model
final class Playlist: Identifiable {
@Attribute(.unique)
var name: String
@Relationship(inverse:…

kai
- 310
- 3
- 14
1
vote
0 answers
Xcode 15 beta 6, SwiftData Framework "Symbol not found" error
When building a ios17 app with SwiftData there is an issue with the Framework not being installed as noted on apple dev forums here: https://developer.apple.com/forums/thread/734970 my machine does not have the Framework folder for SwiftData, is…

medright
- 138
- 10
1
vote
1 answer
Setting up SwiftData with iCloud share - difference to Core Data
How to set up the sharing mechanism with SwiftData (Sharing between users)?
Are there any differences to the tutorials that can be found on this topic for iCloud + Core Data?
When looking at the initializer for Modelconfiguration what does…

sheldor
- 115
- 12
1
vote
1 answer
How do I implement Undo & Redo in SwiftUI using SwiftData in iOS17 Beta 4+
I am playing with SwiftData in an iOS app using XCode 15 Beta 5. Really enjoying the experience so far, very easy to use. My question relates to how can I enable undo and redo functionality when editing an existing entity in a user entry form. The…

apps2go
- 86
- 1
- 6
1
vote
1 answer
SwiftData crash "Illegal attempt to establish a relationship"
I am using SwiftData and SwiftUI, xcode 15 beta 5. I am trying to establish relationships between entities in DB. The is a User, a Book, and an Ownership between them.
struct asdApp: App {
let container = try! ModelContainer(for:…

f3dm76
- 680
- 7
- 21
1
vote
0 answers
Is there any SwiftData equivalent willSave?
With NSManagedObject there are a few hooks like awakeFromInsert() and willSave() among others. Are there methods to override that can serve the same function? awakeFromInsert can be replaced with the init method, but willSave() I currently use to…

Chad
- 382
- 1
- 11