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

后端 未结 5 1262
抹茶落季
抹茶落季 2020-12-10 01:36

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 addItemViewContr         


        
5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-10 02:15

    The possible reason is you didn't tell the ChecklistItem type that it is equatable, maybe you forgot to mention ChecklistItem class is inherited from NSObject.

    import Foundation
    
    class ChecklistItem: NSObject {
      var text = ""
      var checked = false
    
      func toggleChecked() {
        checked = !checked
      }
    }
    

    NSObject adopts or conforms to the equatable protocol

提交回复
热议问题