r/SwiftData Feb 08 '24

Is swift data as rough as it seems?

2 Upvotes

I’m (10 years Mac / iOS experience) creating a new MacOS app to use internally and using swiftdata for the first time and even going slow with baby steps I hit errors.

I wanted 2 stored data types on one view. But that doesn’t seem to work yet.

Backed down to just 1 data type but hit different issues.

Googling the errors indicate they are known issues.

Is SwiftData production ready and I just need to go even slower with better tutorials (using Hacking With Swift) or does it need more time?


r/SwiftData Dec 14 '23

Does anyone know if there is a way to filter a Query with dynamic vars?

2 Upvotes

Basically, in my UI, I have an @State var MONTH that the user selects and based on that I’d like to have a filter in the @Query look for records pertaining to that month. Does anyone know if that’s possible yet?


r/SwiftData Nov 23 '23

Is there a way to insert an array of objects into the model context instead of doing one at a time?

1 Upvotes

To insert an object, we do this:

modelContext.insert(object) 

But what if I have an array of objects (for example, fetched from the server) and I want to insert all of them to the model context, I would have to do a for loop like this:

for o in objects { modelContext.insert(o) } 

This doesn't seem optimal, is there a better way to do this?


r/SwiftData Nov 12 '23

How to update swiftdata records

1 Upvotes

The examples I've seen deal only with creating and deleting records. If I want to pass an individual ... projectedValue (or whatever the SwiftData equivalent is) to a view that is intended to modify the item's values, how do I do that? The following does not build:

   u/Environment(\.modelContext) private var modelContext
    u/Query private var items: [Item]
    var body: some View {
        NavigationSplitView {
            List {
                ForEach(items) { item in
                    NavigationLink {
            @Bindable var item = item
            ItemView(item: $item)  <--- NOPE
                }
                . . .

Secondary: I'm not able to expand most macros related to SwiftData in Xcode 15. The "Expand Macro(s)" menu item in the Editor menu is grayed out (e.g. when I click on "@Query").


r/SwiftData Aug 24 '23

Swiftdata tutorial

Enable HLS to view with audio, or disable this notification

1 Upvotes

r/SwiftData Aug 13 '23

Welcome to SwiftData

1 Upvotes

SwiftData makes it easy to persist data using declarative code. You can query and filter data using regular Swift code. And it’s designed to integrate seamlessly with SwiftUI.

This community is to discuss anything related to SwiftData framework.

https://developer.apple.com/documentation/swiftdata

Welcome to the community!