Here is what I want to do:
protocol GenericFactory {
associatedtype Input
associatedtype Value
func create(with input: Input) -> Value
}
class Base {
var input: Factory.Input {
preconditionFailure("To be overriden")
}
}
protocol ValueProtocol {}
struct SomeInputImpl {}
protocol ValueFactory: GenericFactory where Input == SomeInputImpl, Value: ValueProtocol {}
class Child: Base {
override var input: Factory.Input {
return SomeInputImpl()
}
}
On the line swift override var input: Factory.Input { I'm getting an error Property 'input' with type 'SomeInputImpl' cannot override a property with type 'Factory.Input'. I do not understand the reason of this error as the type of input is described in ValueFactory protocol, but because of some reasons swift interprets the Factory.Input in base and Factory.input in Child as different types. Can someone please explain me what's wrong here?
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)