So I know a class can only inherit a single class but can inherit multiple protocols. I am looking at some code here and confused as to why swift is throwing me an error.
protocol PaymentViewModelConfigurable: ViewModelWithResult {
}
class ViewModelWithResult {
func printWithResultClass() {
print("In View Model with result class")
}
}
class PaymentViewModel: PaymentViewModelConfigurable {
}
class MainOne {
let viewModel: PaymentViewModelConfigurable = PaymentViewModel()
}
So I would assume this is ok because my PaymentViewModel
class inherits a protocol and that protocol inherits from a class.
But if I change the logic to this on my ViewModel to inherit the protocol & the class, its fine
protocol PaymentViewModelConfigurable: ViewModelWithResult {
func payments()
}
class ViewModelWithResult {
func printWithResultClass() {
print("In View Model with result class")
}
}
class PaymentViewModel: ViewModelWithResult, PaymentViewModelConfigurable {
func payments() {
print("Payments")
}
}
class MainOne {
let viewModel: PaymentViewModelConfigurable = PaymentViewModel()
init() {
viewModel.payments()
}
}
These are the errors that come up:
'PaymentViewModelConfigurable' requires that 'PaymentViewModel' inherit from 'ViewModelWithResult'
Type 'PaymentViewModel' does not conform to protocol 'PaymentViewModelConfigurable'