我正在使用switch语句来1)切换复选标记和2)将谓词添加/删除到谓词数组。如果我知道它的名字,但有没有数组中的索引,是否有办法删除一个对象?如果没有,解决方法是什么?这是我的代码的相关部分。在不知道对象索引的情况下从数组中删除对象?
var colorPredicates: [NSPredicate?] = []
// Switch statement
case blueCell:
if (cell.accessoryType == .None) {
colorPredicates.append(bluePredicate)
cell.accessoryType = .Checkmark
println(colorPredicates) // debug code to see what's in there
} else {
let deleteIndex = find(colorPredicates, bluePredicate) // error: NSPredicate doesn't conform to Equatable.
muscleGroupPredicates.removeAtIndex(deleteIndex)
cell.accessoryType = .None
}
default:
println("default case")
找到对象,然后将其删除。如果你将删除多个,则向后索引。没有花哨的代码要求。 –
如何?这是我的问题。 – iOSPadawan
你知道如何使用循环?和“如果”陈述? –