无法调用' indexOf'参数类型为'(ChecklistItem)'的参数列表 [英] Cannot invoke 'indexOf' with an argument list of type '(ChecklistItem)'

查看:73
本文介绍了无法调用' indexOf'参数类型为'(ChecklistItem)'的参数列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我编写代码以使用indexOf从数组中查找项目时,它向我显示了上述错误.这是我的代码:-

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)
        }
    }

推荐答案

为了使用 indexOf ChecklistItem 必须采用

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

这篇关于无法调用' indexOf'参数类型为'(ChecklistItem)'的参数列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆