Post

Replies

Boosts

Views

Activity

Reply to Context outside of SwiftUI Views
It seems no method to get the mainContext injected in environment directly, and the context is not sendable, you can not use it on other actor/thread. But you can get the context from your model like model.context. actor BackgroundActor: ModelActor { nonisolated public let executor: any ModelExecutor init(container: ModelContainer) { let context = ModelContext(container) executor = DefaultModelExecutor(context: context) } func run(task: (ModelContext) -> Void) { task(context) } } You can use this wrapper like this: databaseActor.run { context in // .... }
Jul ’23
Reply to How to count rows in SwiftData?
AFAIK Create a view history table and apply cascade rule
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Oct ’23
Reply to Context outside of SwiftUI Views
It seems no method to get the mainContext injected in environment directly, and the context is not sendable, you can not use it on other actor/thread. But you can get the context from your model like model.context. actor BackgroundActor: ModelActor { nonisolated public let executor: any ModelExecutor init(container: ModelContainer) { let context = ModelContext(container) executor = DefaultModelExecutor(context: context) } func run(task: (ModelContext) -> Void) { task(context) } } You can use this wrapper like this: databaseActor.run { context in // .... }
Replies
Boosts
Views
Activity
Jul ’23
Reply to Pass @Query filter predicate from parent view in SwiftData
Deleted
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jun ’23
Reply to Inserting a Model entity with a relationship results in a runtime error.
@Relationship(.nullify, inverse: \Group.members) var group: Group group must be optional
Replies
Boosts
Views
Activity
Jun ’23
Reply to Can't test equality of two model entities with a predicate
You should extract a variable for the name. let tmp = other.name #Predicate<OnlyName> { $0.name == tmp }
Replies
Boosts
Views
Activity
Jun ’23
Reply to SwiftData Query relationships not working
How about: ForEach(department.students) { student in Text(student.name) }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jun ’23
Reply to Navigation: update multiple times per frame
Same problem if I append a value to path (NavigationPath). Tested in Xcode 14 beta 5
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Aug ’22
Reply to Unboxing protocol to concrete type in SwiftUI View
I have a similar problem. There is a not elegant solution: force cast. switch item: case is Item1 let binding = Binding(...) RowView(item: binding) default: fatelError("Unknown Item") }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jun ’22