我有一个非常奇怪的错误。一直在学习Swift,并正在阅读有关在这里查找数组中对象索引的文档:https://developer.apple.com/reference/swift/array/1689674-indexindex(of:element)不存在
但是,这种方法在我的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我重视的出现并没有能够给方法的图像找到为什么这可能发生在任何地方的答案。
虽然我知道它存在,但我找不到func index(of:)方法的用法!
我得到以下编译器错误:
ChecklistViewController.swift:186:26: Argument labels '(of:, _:)' do not match any available overloads
ChecklistViewController.swift:186:26: Overloads for 'index' exist with these partially matching parameter lists: (Int, offsetBy: Int), (Self.Index, offsetBy: Self.IndexDistance)
这是您的文章中的错字?它应该是'items.index(of:rowitem)'。请注意'index'而不是'Index'。 – rmaddy
'TaskItem'是否可以等值? – Hamish
这不是,谢谢 – user2219097