Page 195

Swift

self.equations = equations super.init(physics: physics) } }

class Maths: Subjects { var formulae: String init(physics: String, formulae: String) { self.formulae = formulae super.init(physics: physics) } }

let sa = [ Chemistry(physics: "solid physics", equations: "Hertz"), Maths(physics: "Fluid Dynamics", formulae: "Giga Hertz"), Chemistry(physics: "Thermo physics", equations: "Decibels"), Maths(physics: "Astro Physics", formulae: "MegaHertz"), Maths(physics: "Differential Equations", formulae: "Cosine Series")]

let samplechem = Chemistry(physics: "solid physics", equations: "Hertz") println("Instance physics is: \(samplechem.physics)") println("Instance equation is: \(samplechem.equations)")

let samplemaths = Maths(physics: "Fluid Dynamics", formulae: "Giga Hertz") println("Instance physics is: \(samplemaths.physics)") println("Instance formulae is: \(samplemaths.formulae)")

var chemCount = 0 var mathsCount = 0 for item in sa { if item is Chemistry { ++chemCount 183

Swift is a powerful and instinctive programming language for macOS, iOS, watchOS and tvOS....  

...

Advertisement