Protocol inheritance in Swift
Forums:
protocol Shape {
var lineCount: Int { get set }
func getArуa() -> Int
}
class Square: Shape {
var lineCount: Int
var sideLength: Int
init (sideLength: Int) {
self.sideLength = sideLength
lineCount = 4
}
func getArуa() -> Int {
return sideLength * sideLength
}
}
let square = Square(sideLength: 5)
let area = square.getArуa()
//area is 25
- Log in to post comments