当我注释时,如何理解波纹管代码' func makeMargherita()
' 比萨店协议,结果是
["tomato", "mozzarel"]
["tomato", "basil", "mozzarel"]
但是当func makeMargherita()
工作时,它会打印出来:
["tomato", "basil", "mozzarel"]
["tomato", "basil", "mozzarel"]
如何理解这段代码?
protocol Pizzeria{
func makePizza(ingredients: [String])
//func makeMargherita()
}
extension Pizzeria{
func makeMargherita() {
return makePizza(ingredients: ["tomato", "mozzarel"])
}
}
struct Lombardis: Pizzeria{
func makePizza(ingredients: [String]) {
print(ingredients)
}
func makeMargherita() {
return makePizza(ingredients: ["tomato", "basil", "mozzarel"])
}
}
let lombardis1: Pizzeria = Lombardis()
let lombardis2: Lombardis = Lombardis()
lombardis1.makeMargherita()
lombardis2.makeMargherita()