Post

Replies

Boosts

Views

Activity

Swift Data how to get binding from @Query property?
I want to use List(data:, editActions:, rowContent:), the data: needs a $property, but I can't pass $persons in there directly. Is there any way to solve like this below: import SwiftUI import SwiftData struct BindableTest: View { @Environment(\.modelContext) var modelContext @Query var persons: [Person] var body: some View { VStack { Button("Add") { let person = Person(name: "test", age: 12) modelContext.insert(person) } List($persons, editActions: .all) { $person in Text(person.name) Text(person.age.formatted()) } } } } iOS 17
0
3
936
Feb ’24