Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot invoke 'indexOf' with an argument list of type '(ChecklistItem)'

Tags:

When I am writing code for finding an item from the array with the use of indexOf it shows me the above stated error. Here is my code:-

func addItemViewController(controller: AddItemViewController, didFinishEditingItem item: ChecklistItem) {     if let index = items.indexOf(item)     {         let indexPath = NSIndexPath(forRow: index, inSection: 0)          if let cell = tableView.cellForRowAtIndexPath(indexPath)         {             configureTextForCell(cell, withChecklistItem: item)         }     } 
like image 341
shahin ali agharia Avatar asked Aug 06 '15 09:08

shahin ali agharia


1 Answers

In order to use indexOf the ChecklistItem must adopt Equatable protocol. Only by adopting this protocol the list can compare an item with other items to find the desired index

like image 98
Zell B. Avatar answered Sep 20 '22 13:09

Zell B.