泛型的泛型数组,其中泛型是父类

时间:2017-06-19 12:42:42

标签: arrays swift oop generics

我遇到了一些泛型问题。

我有:

class SyncRequest<Type>: ApiRequest<Type> where Type:SyncableModel {} // really empty. Used only for tipisation

class SyncableModel: BaseModel {...} // BaseModel is class also

class SyncServiceImpl: SyncService {
    private var registeredRequests: [SyncRequest<SyncableModel>]
    init() {
        registeredRequests.append(SyncRequest<EventGroup>("{somepath}"))
    }
}

但是有一个错误说

  

&#34;无法转换类型&#39; SyncRequest&lt; .EventGroup&gt;&#39;的值预期   参数类型&#39; SyncRequest&lt; .SyncableModel&gt;&#39;&#34;

有没有办法将子类用作泛型类型?

0 个答案:

没有答案