0
考慮下面的代碼:奇怪的編譯器錯誤與斯威夫特協議從可切片的繼承和添加單個屬性
protocol CollectionStreamType: Sliceable {
var position: Index { get set }
}
class Cell<T> {
let contents: T
init(_ contents: T) {
self.contents = contents
}
}
enum ParseResult<T, E> {
case Matched([T])
case NotMatched
case Err(Cell<E>)
}
func then<S: CollectionStreamType, T, E where S.SubSlice == S>(parsers: [S -> ParseResult<T, E>])(stream: S) -> ParseResult<T, E> {
let position = stream.position
// ERROR IS HERE: Type '()' does not conform to protocol 'GeneratorType'. WTH?
stream.position = position
return .NotMatched
}
我正在寫一個解析器組合庫斯威夫特叫吝嗇。它運作良好,但我最近決定用協議CollectionStreamType
替換我的具體收集類型。當我這樣做時,我開始有問題。
此代碼不能直接從我的解析器組合庫,但它提煉了問題的本質,並確實對我看到的錯誤,如下所示:
類型「()」不符合協議'GeneratorType'。
我感到困惑。任何人都有如何解決這個問題的見解?
我不知道我可以只做一個協議類。我怎麼做? –
'Protocol CollectionStreamType:class,Sliceable {' –
你每天都會學到新的東西。這就是我要做的。 –