我有一个 Objective-C 类(恰好是一个按钮,但这并不重要),在我的(混合语言)项目的另一部分,我有一个这些按钮的数组,我想获得索引使用该find()
方法的按钮。像这样:
func doSomethingWithThisButtonIndex(index:Int)
{
let buttons = [firstButton, secondButton, thirdButton]
if index == find(buttons, firstButton)
{
// we've selected the first button
}
}
但我得到了
类型 'ImplicitlyUnwrappedOptional' 不符合协议 equatable
好的,让我们使用 Objective-C 并实现 ButtonThing <Equatable>
。但它不承认这一点。
那我该怎么办?现在我正在围绕它进行构建,强制数组成为 NSArray 并使用indexOfObject
. 但这很丑陋。并且令人沮丧。