我的项目中有以下数组:
var bottom = [[CGPoint]]() // bottom = [bottom1,...,bottom5]
var left = [[CGPoint]]() // left = [left1,...,left5]
var top = [[CGPoint]]() // top = [top1,..., top5]
var right = [[CGPoint]]() // right = [right1,...,right5]
var bottomExtended = [[CGPoint]]()
directionArray = [right, bottom, left, top]
enum Direction: Int {
case right = 0, bottom, left, top
}
bottom
和bottomExtended
的长度相同。我使用以下代码将它们合并成功:
for i in 0..<bottom.count {
bottom[i].appendContentsOf(bottomExtended[i])
}
我写了一个合并数组的通用函数:
func addToDirectionArray (direction:Direction, addArray:[[CGPoint]]) {
let enumRawValue = direction.rawValue
for i in 0..<directionArray[enumRawValue].count {
directionArray[enumRawValue][i].appendContentsOf(addArray[i])
}
}
我测试了以下内容:
addToDirectionArray(.bottom, addArray: bottomExtended)
但它没有合并数组。我检查了数组计数。我该如何解决这个问题?