Skip to content
Discussion options

You must be logged in to vote

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 else for your Case().when because you specifically want nil when the condition is not true, and that is the default behavior as detailed in the SQLite docs I linked to above:

If there is no ELSE expression and none of the WHEN expressions are true, then the overall result is NULL.

And so this compiles just fine for me:

@Table struct Foo {
  var isOn = false
  var date: Date?
}
func foo() {
  Foo.update {
    $0.date = Case().when($0.isOn, then: Date())
  }
}

Is it not compiling for you?

And if in the future you do need an else clause, it is not d…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@mbrandonw
Comment options

Comment options

You must be logged in to vote
1 reply
@mbrandonw
Comment options

Answer selected by StewartLynch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants