我实现了自定义类
class DisplayItem: NSObject {
…
}
在我的应用中正常工作。
它使用函数findDisplayItemTableDifferences1
来确定两个2-dim数组之间的差异。第一维是tableView
的部分,第二维是部分的行。第2行由DisplayItem
类型的元素组成:
func findDisplayItemTableDifferences1(oldTable: [[DisplayItem]],
newTable: [[DisplayItem]]) -> (deletions: [IndexPath], insertions: [IndexPath], movements: [(from: IndexPath, to: IndexPath)], updates: [IndexPath]) {
…
}
为了测试应用程序,我编写了单元测试的第一步:
func test_cellOperations() {
// Given
let shoppingItem1 = ShoppingItem.init(name: "Item1")
let displayItem1 = DisplayItem.init(shoppingItem: shoppingItem1)
let oldTable: [[DisplayItem]] = [[displayItem1]]
var differences: (deletions: [IndexPath], insertions: [IndexPath], movements: [(from: IndexPath, to: IndexPath)], updates: [IndexPath])
// When
differences = ItemsViewModel.shared.findDisplayItemTableDifferences1(oldTable: oldTable, newTable: [[]])
}
此函数无法编译。它在行differences =
处创建,特别是在参数oldTable: oldTable
处创建错误:
Cannot convert value of type '[[DisplayItem]]' to expected argument type '[[DisplayItem]]'
我认为这是一个iOS编译错误,至少错误信息很奇怪。
知道如何继续吗?