在我的应用程序中,当选择单元格时我在数组中添加了一个对象,当重新选择单元格时取消选择并删除对象。我用了那个代码,但给我错误。
extension Array {
func indexOfObject(object : AnyObject) -> NSInteger {
return (self as NSArray).indexOfObject(object)
}
mutating func removeObject(object : AnyObject) {
for var index = self.indexOfObject(object); index != NSNotFound; index = self.indexOfObject(object) {
self.removeAtIndex(index)
}
}
}
class MyViewController: UITableViewController {
var arrContacts: [Any] = []
var contacts: [Any] = []
func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
arrContacts.removeObject(contacts[indexPath.row])
}
}
它给了我两个这样的错误:
C-style for statement has been removed in Swift 3
Value of type '[Any]' has no member 'removeObject'