【发布时间】:2017-02-11 02:33:21
【问题描述】:
我正在尝试制定一个可以接受 X 类型对象集合的委托协议。该协议的相同方法应该能够接受以下实例:
Set<X>Array<X>-
LazyMapCollection<Dictionary<_, X>, X>(最后一个来自Dictionary.values)
问题是,如何声明协议方法?
以下是一些不太正确的候选方法声明:
public protocol BlahDelegate : NSObjectProtocol {
// won't compile; 'cannot specialize generic type "Sequence"'
func blah(_ sender: Blah,foundStuff stuff: Sequence<Stuff>)
// won't compile; 'cannot specialize generic type "Collection"'
func blah(_ sender: Blah,foundStuff stuff: Collection<Stuff>)
// this can't take in Set<Stuff> nor LazyMapCollection<Dictionary<_, Stuff>, Stuff>
func blah(_ sender: Blah,foundStuff stuff: Array<Stuff>)
// this can't take in Array<Stuff> nor LazyMapCollection<Dictionary<_, Stuff>, Stuff>
func blah(_ sender: Blah,foundStuff stuff: Set<Stuff>)
}
PS:这是为 Swift 3 准备的。
【问题讨论】: