Protocols composition in Swift
Forums:
protocol PId {
var id: Int {get}
}
protocol Priced {
var price: Double {get}
}
struct Goods: PId, Priced {
var id: Int
var price: Double
}
func showIdAndPrice(info: protocol<PId, Priced>) {
print("id = \(info.id), price = \(info.price)")
}
let bread = Goods(id: 1, price: 35.5)
showIdAndPrice(bread) //<-Error?
- Log in to post comments