This is by far the most faved/retweeted Swift tip of mine lately:
don't forget you can do this 🎉 in Swift #swiftlang pic.twitter.com/izVlfcqOYv
— Marcin Krzyzanowski (@krzyzanowskim) November 10, 2015
indeed cool, unexpected and forgettable feature of Swift pattern-matching.
The fact is you can use where
keyword in a case label of a switch
statement, a catch
clause of a do statement, or in the case condition of an if
, while
, guard
, for-in
statement, or to define type constraints.
for-in
do-catch
while
if
guard
switch-case
type constraint
pity though, where keyword
is not really described in details by the "The Swift Programming Language` book.
anyway... now it's clear. Gist code is here.
Conclusion
Of course where
is part of control flow of Swift program and may be used almost everywhere.