Replies: 1 comment 2 replies
-
Hi @gorpello, the library does not provide this tool directly because the only way to know that information is to query the database. A simple computed property of a value type cannot have knowledge of whether or not it is persisted do the database. But we do provide the tools that make it possible to figure this out by thinking about the problem a little differently. To start with, if you have an That allows you to represent an item that has not yet been inserted into the database when @Table
struct Item {
var id: Int
var title = ""
}
struct ItemForm: View {
@State var item: Item.Draft
var body: some View {
if item.id == nil {
// New item
} else {
// Existing item
}
}
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Thank you for your great work on this project!
I have a use case where I fetch a list of items from an external API, and the user can save or unsave items.
In my UI, I need to show different states depending on whether an item is already stored in the database or not (for example, show a “Save” button if not stored, or “Remove” if it already exists).
Is there already a mechanism in this library to expose whether a @table element is stored in the database (e.g. a computed isStored property)?
Or, if not, what would be the recommended way to model this use case?
I was wondering if something like this could make sense:
`@Table
struct Item {
var id: Int
var title: String
}`
Thanks a lot for your time.
Any advice or best practice would be greatly appreciated!
Beta Was this translation helpful? Give feedback.
All reactions