Swift: typealias for composition type

时间:2015-08-07 02:42:56

标签: objective-c swift

In Objective-C, I could declare a class a subclass and conform to a protocol:

@interface SubClass : ParentClass<OneProtocol>

When bridged to Swift 1.x, SubClass becomes

class SubClass : ParentClass, OneProtocol

I find it difficult to use this kind of composite type. For example, without using generics, how to say a function returns an instance of a ParentClass that conforms to OneProtocol?

I know if it is two protocols, we can use protocol<OneProtocol, TwoProtocol>. But here one of them is class.

Ideally there is a syntax to declare this as a typealias. But if it is not possible, the last resort is to compose in Objective-C, and bridge the composition to Swift.

1 个答案:

答案 0 :(得分:0)

我相信这是Swift的Generics的工作。但显然it is not possible在Swift中实现了相同的Obj-C行为。