protocol

86 阅读1分钟

protocol Name

{

var myName:String? (get set)

}

protocol Age

{

var myAge:Int? (get set)

}

class Cat:Name,Age

{

var myName:String?

var myAge: Int?

}

func printCatInfo(info inputInfo:Name&Age)

{

print(inputInfo.myName ?? "n i l")

print(inputInfo.myAge ?? 0)

}

let cat = Cat()

cat.myName = "lusi"

car.MyAge = 2

self.printCatInfo(info: cat)