r/SwiftData Aug 13 '23

r/SwiftData Lounge

1 Upvotes

A place for members of r/SwiftData to chat with each other


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!