【发布时间】:2017-02-22 15:34:40
【问题描述】:
我有一个非常奇怪的错误。一直在学习 Swift,正在阅读有关在数组中查找对象索引的文档:https://developer.apple.com/reference/swift/array/1689674-index
但是这个方法在我的 Xcode 中不存在。
这是一个例子:
var items : [TaskItem]
items = [TaskItem] ()
let rowitem = TaskItem()
rowitem.text = "helloworld"
items.append(rowitem)
//Attempting to find the index of an object
items.Index(of: rowitem)
//错误 - Xcode 找不到我正在寻找的特定函数
我附上了出现的方法的图像,但无法找到为什么这可能会在任何地方发生的答案。
我找不到 func index(of:) 方法的用途,虽然我知道它存在!
我收到以下编译器错误:
ChecklistViewController.swift:186:26: 参数标签 '(of:, _:)' do 不匹配任何可用的重载
ChecklistViewController.swift:186:26: 'index' 的重载存在于 这些部分匹配的参数列表:(Int, offsetBy: Int), (Self.Index, offsetBy: Self.IndexDistance)
【问题讨论】:
-
这是您帖子中的错字吗?应该是
items.index(of: rowitem)。注意index而不是Index。 -
是
TaskItemEquatable?