Thanks for everybodys suggestions. I'm still plugging away on this. Yes, my requirements are array mutability and the ability to write type specific extensions.
Interestingly this works:
extension Array where Element : IntegerType {
mutating func addItems() {
self.append(1)
self.append(2)
}
}
var myIntArray = [Int]()
myIntArray.addItems()
However... I tried to do it with some simple types of my own and it doesn't...
protocol MyProtocol {}
struct MyContent : MyProtocol { let content = 1 }
extension Array where Element : MyProtocol {
mutating func addItems() {
self.append(MyContent())
self.append(MyContent())
}
}
var myArray = [MyProtocol]()
// myArray.append(MyContent())
myArray.addItems()
Error on self.append(): Can't invoke append with an argument list of (MyContent).
Any thoughts greatly appreciated.