In my application I added one object in array when select cell and unselect and remove object when re-select cell. I used that code but give me error.
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])
}
}
It gives me 2 error like that:
C-style for statement has been removed in Swift 3
Value of type '[Any]' has no member 'removeObject'
Set<Contact>rather than an Array. Can you provide more information about your contact object? If you have made it yourself you will need it to conform toHashableandEquatablein order to put it in a set