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

后端 未结 5 1259
抹茶落季
抹茶落季 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:09

    indexOf can only be applied to Collections of Equatable types, your ChecklistItem doesn't conform to Equatable protocol (have an == operator).

    To be able to use indexOf add this to the file containing ChecklistItem class in the global scope :

    func ==(lhs: ChecklistItem, rhs: ChecklistItem) -> Bool {
        return lhs === rhs
    }
    
    Swift3: 
    public static func ==(lhs: Place, rhs: Place) -> Bool {
            return lhs === rhs
        }
    

    Please note it will make comparison by comparing instances addresses in memory. You may want to check equality by comparing members of the class instead.

提交回复
热议问题