O'Reilly logo

Swift Functional Programming - Second Edition by Dr. Fatih Nayebi

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 enumeration case pattern

An enumeration case pattern matches a case of an existing enumeration type. Enumeration case patterns appear in a switch statement's case labels and case conditions of if, while, guard, and for-in statements.

If the enumeration case that we are trying to match has any associated values, the corresponding enumeration case pattern must specify a tuple pattern that contains one element for each associated value. The following example presents the enumeration case pattern:

let dimension = Dimension.metric(9.0, 6.0) func convert(dimension: Dimension) -> Dimension {     switch dimension {     case let .us(length, width):         return .metric(length * 0.304, width * 0.304)     case let .metric(length, width):  return .us(length * ...

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