0
我想创建一个ObservableType
的扩展,但下面的代码不会编译。RxSwift generic'不能将类型'(_) - > [Any]'的值转换为期望的参数类型'(String) - > _'`
public extension ObservableType {
public func foo<C: Collection>(_ calls: @escaping (E) -> C) -> Observable<[Any]> where C.Iterator.Element: ObservableType {
return flatMap { input in Observable.zip(calls(input)) { objects in objects }
}
}
}
// compile error
Observable.just("foo")
.foo { foo in
[Observable.just(User()), Observable.just(Repo())]
}
它抛出一个错误:Cannot convert value of type '(_) -> [Any]' to expected argument type '(String) -> _'
我不知道问题出在哪里。在此先感谢
我想混合类型? – akabc
@akabc我更新了答案 –
是否可以修改'foo'函数以使客户端代码无错地编译? – akabc