Does using let _ = ... have any purpose?
I have seen the question and answers. What is the underscore representative in Swift References? , and I know that underscores can be used to represent a variable that is not needed .
This would make sense if I needed only one tuple value, as in the example from the link above:
let (result, _) = someFunctionThatReturnsATuple()
However, I recently met this code :
do { let _ = try DB.run( table.create(ifNotExists: true) {t in t.column(teamId, primaryKey: true) t.column(city) t.column(nickName) t.column(abbreviation) }) } catch _ { // Error throw if table already exists }
I don't get any warnings or compiler errors if I just delete let _ = . It seems to me that it is easier and more understandable.
try DB.run( table.create(ifNotExists: true) {t in t.column(teamId, primaryKey: true) t.column(city) t.column(nickName) t.column(abbreviation) })
The author of the code wrote a book and blog about Swift . I know that the authors are not infallible, but it made me wonder if there is something that I do not see.
source share