无法使用类型'(ChecklistItem)'的参数列表调用'indexOf'

编程入门 行业动态 更新时间:2024-10-27 11:16:16
本文介绍了无法使用类型'(ChecklistItem)'的参数列表调用'indexOf'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当我使用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 必须采用 Equatable protocol 。只有采用此协议,列表才能将项目与其他项目进行比较,以找到所需的索引

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

更多推荐

无法使用类型'(ChecklistItem)'的参数列表调用'indexOf'

本文发布于:2023-11-26 16:37:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634403.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:参数   类型   列表   ChecklistItem   indexOf

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!