1
Swift中的詞典不符合ExtensibleCollectionType
。因爲它會很容易把它擴大(它在某種程度上不與雨燕1.2的工作;利用斯威夫特2):詞典不符合ExtensibleCollectionType
extension Dictionary: ExtensibleCollectionType {
// ignoring this function
mutating public func reserveCapacity(n: Int) {}
mutating public func append(x: Dictionary.Generator.Element) {
self[x.0] = x.1
}
mutating public func extend<S : SequenceType where S.Generator.Element == Dictionary.Generator.Element>(newElements: S) {
for x in newElements {
self.append(x)
}
}
}
如果這樣做還可以添加字典(參見:Adding SequenceTypes)
標準庫中沒有實現這個好處嗎?
我看不到這樣做的有害後果。你應該提交一個錯誤報告。 –
Swift 1.2中的錯誤(在Swift 2中解決了)還是在標準庫中實現這個錯誤? – Qbyte
這是一個建議。 –