我已經習慣了不斷崩潰的Swift編譯器,通常有很多可用的解決方法。 但是,這次我無法成功地使結構符合MutableCollectionType
。如何在不崩潰編譯器的情況下實現MutableCollectionType?
只要您不註銷MutableCollectionType
一致性,就可以將所附示例粘貼到遊樂場中。
我避免了所有方法的具體實現來縮小崩潰的原因(因此所有的fatalError()
)。但即使方法正確實施,編譯器也會崩潰。
有沒有人有一個想法如何解決這個編譯器崩潰?
struct Test {}
struct TestCollection: CollectionType {
typealias Index = Int
private var values: [Test]
var count: Int {
fatalError()
}
var endIndex: Int {
fatalError()
}
func generate() -> IndexingGenerator<Array<Test>> {
fatalError()
}
var isEmpty: Bool {
fatalError()
}
subscript(bounds: Range<Int>) -> ArraySlice<Test> {
fatalError()
}
subscript(position: Int) -> Test {
get { fatalError() }
mutating set { fatalError() }
}
var startIndex: Int {
fatalError()
}
}
// uncommenting the following line crashes the compiler
// extension TestCollection: MutableCollectionType {}
比較的http://計算器.com/questions/32668635/swift-minimum-implementation-for-types-conforming-to-protocols-with-default-impl用於(可變)CollectionType的最小實現。 –