So, I have a protocol, and in it I want a class type variable. That way I can initialize this class from a variable.
Keep in mind that there will be many different classes. I made a quick example.
I get the error "type 'CashRegister' does not match the protocol 'RegisterProtocol'"
This example is not exactly what I am doing, but it makes sense. Thanks for the help.
protocol RegisterProtocol {
var currentBill: DollarBillProtocol {get set}
func makeNewBill()->DollarBillProtocol
}
extension RegisterProtocol {
func printCurrentBill() {
Swift.print(currentBill)
}
}
class CashRegister: RegisterProtocol {
var currentBill = OneDollarBill.self
func makeNewBill() -> DollarBillProtocol {
return currentBill.init()
}
}
protocol DollarBillProtocol {
}
class OneDollarBill: DollarBillProtocol {
required init(){
}
}
class FiveDollarBill: DollarBillProtocol {
required init(){
}
}
source
share