I'm trying to make an Extension to the Array type so to be able to work with 2D arrays. In fact, I did this in Objective-C and the code below worked like a charm. But I really stuck in Swift.
extension Array {
mutating func addObject(anObject : AnyObject, toSubarrayAtIndex idx : Int) {
while self.count <= idx {
let newSubArray = [AnyObject]()
self.append(newSubArray)
}
var subArray = self[idx] as! [AnyObject]
subArray.append(anObject)
}
func objectAtIndexPath(indexPath : NSIndexPath) -> AnyObject {
let subArray = self[indexPath.section] as! Array
return subArray[indexPath.row] as! AnyObject
}
}
I get this error no matter what I do:
Error: Cannot invoke 'append' with an argument list of type '([AnyObject])'
I'd appreciate any help.