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

Page 220

Swift

Protocol Inheritance Swift allows protocols to inherit properties from its defined properties. It is similar to that of class inheritance, but with the choice of listing multiple inherited protocols separated by commas. protocol classa { var no1: Int { get set } func calc(sum: Int) }

protocol result { func print(target: classa) }

class student2: result { func print(target: classa) { target.calc(1) } }

class classb: result { func print(target: classa) { target.calc(5) } }

class student: classa { var no1: Int = 10

func calc(sum: Int) { no1 -= sum println("Student attempted \(sum) times to pass")

if no1 <= 0 { println("Student is absent for exam") } } 208


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.