I'd like to add an extension to array of arrays to retrieve an Element with the IndexPath of size 2:
let array: [[String]] = ....
let indexPath = IndexPath(indexes: [0, 0])
let string = array[indexPath]
I'm getting an error cannot assign through subscript subscript is get-only while implementing the following extension:
extension Array where Element : Collection, Element.Index == Int {
subscript(indexPath: IndexPath) -> Element.Iterator.Element {
get {
return self[indexPath.section][indexPath.item]
}
set {
self[indexPath.section][indexPath.item] = newValue
}
}
}
What is the reason for such an error? How can I add a mutation option to the subscript?