April 2017
Intermediate to advanced
316 pages
9h 33m
English
There are two types of casting patterns as follows:
The following example presents the is and as type casting patterns:
let anyValue: Any = 7 switch anyValue { case is Int: print(anyValue + 3) case let ourValue as Int: print(ourValue + 3) default: () }
The anyValue variable is type of Any storing, an Int value, then the first case is going to be matched but the compiler will complain, as shown in the following screenshot:

We could cast anyValue to Int with as! to resolve the issue. ...
Read now
Unlock full access