Swift: types for composition type
In Objective-C, I can declare a class as a subclass and conform to the protocol:
@interface SubClass : ParentClass<OneProtocol>
When migrating to Swift 1.x, SubClass
it becomes
class SubClass : ParentClass, OneProtocol
I find it difficult to use this type of composite type. For example, without using generics, how do you say the function returns an instance ParentClass
that matches OneProtocol
?
I know if these are two protocols we can use protocol<OneProtocol, TwoProtocol>
. But here one of them is a class.
Ideally there is a syntax for declaring this as typealias. But if this is not possible, in the latter case you need to compose Objective-C and combine composition with Swift.
source to share
I believe this is a job for Swift Generics. But apparently it is not possible to achieve the same Obj-C behavior in Swift.
source to share