chaining in a guard with a let

Is there a way to get guard to setup a let in the first part and then a conditional on the second part?


guard let tags = item.tags && tags.count > 0 else {

return

}


https://www.dropbox.com/s/0a1vsfd2ucqcg6u/Screenshot%202015-06-20%2017.44.46.png?dl=0


I've only been using Swift for 3 days so…:)

Accepted Answer

You can do:


guard let tags = item.tags where tags.count > 0 else


The general syntax of a 'let' test is a series of clauses separated by commas. Each clause is of the form 'let var = initializer where constraint', except that the first clause may alternatively be a pure boolean expression (no 'let') if you wish — and the 'where' constraint is optional, of course.

chaining in a guard with a let
 
 
Q