Chapter 14, Page 307 - Cannot invoke 'index' with an argument list of type '(of: ChecklistItem)'

I’m trying to implement the delegate method for editing checklist items but i get the error - Cannot invoke ‘index’ with an argument list of type ‘(of: ChecklistItem)’

I did some testing in a playground with arrays and i still got the same error. Does index(of:) not work with custom types?

index(of:) works fine with ChecklistItem types since the code in the book was verified at the time of writing the book :slight_smile: You can always try compiling the included sample projects for each chapter to see if the sample project shows the same issue you’re seeing. If not, then the issue is somewhere in your code.

If the sample project does show the same error, then let me know the Xcode version that you’re using since I just tested with the latest Xcode (9.3) and the code compiles fine without any issue at this end.

Hey Fahim, so i compared my project to the sample project and when creating the ChecklistItem class it didn’t say in my copy of the book to inherit from the NSObject class. I also did some more research and found that index(of:) doesn’t work on custom types unless they conform to the Equatable protocol.

Thanks for the quick reply, i’m really new to the whole forums idea and normally feel uncomfortable to ask a question. :slightly_smiling_face:

Edit: Just realised it does address this error later on in the book

I was just about to tell you that page 313 covers that issue - I am going by the PDF file page numbers since they are the only ones which remain constant. If you are using the EPUB version, the page numbers might be different.

And don’t feel uncomfortable about asking questions - the forums are there just for you to clarify things that you might not understand. So use them :smiley:

This topic was automatically closed after 166 days. New replies are no longer allowed.