Repository navigation
Getter for 'subscript(dynamicMember:)' is unavailable #305
Answered
by
mbrandonw
StewartLynch
asked this question in
Q&A
|
I want to update a row with a swipe action as is done in the Reminders example and that works fine when toggling a bool, but I also want to update another property based on that updated boolean. Button(item.isArchived ? "Unarchive" : "Archive"
withErrorReporting {
try database.write { db in
try Item
.find(item.id)
.update {
// this give me an error Getter for 'subscript(dynamicMember:)' is unavailable
if $0.isArchived {
$0.archiveDate = Date.now
} else {
$0.archiveDate = nil
}
// This works fine for toggling the boolean
$0.isArchived.toggle()
}
.execute(db)
}
}
}
.tint(item.isArchived ? .yellow : .green) |
Answered by
mbrandonw
Nov 24, 2025
Replies: 2 comments 2 replies
|
I solved this by doing this, but I am wondering if there is a better way to do it. Button(item.isArchived ? "Unarchive" : "Archive") {
let updatedDate = item.isArchived ? nil : Date.now
withErrorReporting {
try database.write { db in
try Item
.find(item.id)
.update {
$0.isArchived.toggle()
$0.archiveDate = updatedDate // Set archiveDate to nil when unarchiving or Date.now if archiving
}
.execute(db)
}
}
}
.tint(item.isArchived ? .yellow : .green) |
1 reply
|
This is good for a single case, but I am having problems determining how to do the else clause with case(). CASE/WHEN/THEN/ELSE Perhaps I should stop asking questions until I have completed the SQLite series |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @StewartLynch, this isn't something we cover explicitly in our SQLiteData series, and is more related to SQL in general.
You do not need an
elsefor yourCase().whenbecause you specifically wantnilwhen the condition is not true, and that is the default behavior as detailed in the SQLite docs I linked to above:And so this compiles just fine for me:
Is it not compiling for you?
And if in the future you do need an else clause, it is not d…