Arrays 是否在不知道对象索引的情况下从数组中删除对象?

Arrays 是否在不知道对象索引的情况下从数组中删除对象?,arrays,core-data,ios8,xcode6,nspredicate,Arrays,Core Data,Ios8,Xcode6,Nspredicate,我使用switch语句1切换复选标记,2向谓词数组添加/删除谓词。如果我知道一个对象的名称,但不知道它在数组中的索引,有没有办法删除它?如果没有,解决办法是什么?这是我代码的相关部分 var colorPredicates: [NSPredicate?] = [] // Switch statement case blueCell: if (cell.accessoryType == .None) { colorPredi

我使用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")

我错过了一个“!”,它生成了一个编译器错误

我发现这篇文章很有帮助:


由于缺少阵列的Swift方法以及NSSet概念,人们感到有些沮丧。你有没有考虑过向NSArray投球


另外,我认为您的数据源设计中有一个缺陷:您不应该检查单元格的accessoryType来做其他事情。这些信息应该在您的数据源中,而不是在一些任意的UI设计元素中

找到对象,然后将其删除。如果要删除多个,请向后索引。不需要花哨的代码。怎么做?这是我的问题。你知道如何使用循环吗?如果有陈述呢?是的。我想我需要一行代码将其从索引中删除。我将向数组中添加一些东西switch语句将有20个左右的大小写,我知道数组中项目的名称。我只是想弄清楚如何在一个不确定的索引中找到已知的项,如果在一个接口上切换了复选标记,那么如何删除它们。我在else语句中尝试了“let deleteIndex=findcolorPredicates,bluePredicate”,并在“removateIndex:deleteIndex”中使用,但不起作用。所讨论的视图是一个UITableView,具有静态单元格,其中包含供用户检查的选项。switch语句更新用户界面,告诉用户他/她是否选择了谓词,并将其从谓词数组中添加/删除。再深入一点,我发现了另一篇你回复的帖子,内容一针见血:我正在尝试做什么。
// 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)
                colorPredicates.removeAtIndex(deleteIndex!)
                cell.accessoryType = .None
                }
        //more cases within switch statement

        default:
            println("default case")
var colorPredicates = [NSPredicate]() as NSArray
colorPredicates.removeObject(bluePredicate)