O'Reilly logo

Learning Swift™ Programming by Jacob Schatz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The where Clause

If you wanted to provide an extra utility knife for the List collection, you could write a couple functions that do some useful stuff to the List. You will have very strict criteria for the parameters of the function, even more strict than a protocol. Enter the where clause! You can specify that parameters must meet certain criteria before being passed in. This of it like a bouncer at a club. Let’s say you were comparing two Lists—you would want to make sure that both Lists being passed in meet the criteria of a List. You could make a function that will combine all Lists passed in and deDup them all at once, leaving you with one list with all unique values:

protocol Bucket {    typealias SomeItem ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required