Junior — Middle
Is it possible to declare an extension protocol in a declaration with another protocol to inherit its properties?
sobes.tech AI
Answer from AI
In Swift, protocols can inherit properties and methods from other protocols. However, extension protocols are not declared separately — extensions are applied to existing protocols.
If you want one protocol to inherit from another, you declare it explicitly:
protocol A {
func methodA()
}
protocol B: A {
func methodB()
}
Here, protocol B inherits from protocol A and requires the implementation of both methods.
Protocol extensions (extension) allow adding method implementations but do not declare a new protocol with inheritance. Thus, declaring an extension protocol with inheritance of properties from another protocol can only be done through regular protocol inheritance, not through extensions.