Page 200

Swift

exampleany.append(3.14159) exampleany.append("Example for Any") exampleany.append(Chemistry(physics: "solid physics", equations: "Hertz"))

for print in exampleany { switch print { case let someInt as Int: println("Integer value is \(someInt)") case let someDouble as Double where someDouble > 0: println("Pi value is \(someDouble)") case let someString as String: println("\(someString)") case let phy as Chemistry: println("Topics '\(phy.physics)', \(phy.equations)") default: println("None") } } When we run the above program using playground, we get the following result: Instance physics is: solid physics Instance equation is: Hertz Instance physics is: Fluid Dynamics Instance formulae is: Giga Hertz Chemistry topics are: 'solid physics', Hertz Maths topics are: 'Fluid Dynamics',

Giga Hertz

Chemistry topics are: 'Thermo physics', Decibels Maths topics are: 'Astro Physics',

MegaHertz

Maths topics are: 'Differential Equations',

Cosine Series

Integer value is 12 Pi value is 3.14159 Example for Any Topics 'solid physics', Hertz

188

​Swift is just a effective and user-friendly programming language for macOS, iOS, watchOS and ...  

...

Advertisement