Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 3:二进制运算符'==';不能应用于两个';indexath';操作数_Swift_Swift3 - Fatal编程技术网

Swift 3:二进制运算符'==';不能应用于两个';indexath';操作数

Swift 3:二进制运算符'==';不能应用于两个';indexath';操作数,swift,swift3,Swift,Swift3,错误来自于此。这在Swift 2.3下运行良好 selectedIndexPaths = selectedIndexPaths.filter() { $0 !== indexPath} 其中: var selectedIndexPaths: [IndexPath] = [] 有什么建议吗?只需使用= 将索引作为参考进行比较是没有意义的 indepath是一个结构(与类类型的nsindepath相比),因此无法比较引用。然而,它从来没有真正意义。只要比较它们是否相等。除了Sulthan所说的:

错误来自于此。这在Swift 2.3下运行良好

selectedIndexPaths = selectedIndexPaths.filter() { $0 !== indexPath}
其中:

var selectedIndexPaths: [IndexPath] = []

有什么建议吗?

只需使用
=

将索引作为参考进行比较是没有意义的


indepath
是一个结构(与类类型的
nsindepath
相比),因此无法比较引用。然而,它从来没有真正意义。只要比较它们是否相等。

除了Sulthan所说的:如果您将
选择的索引路径定义为
一套


这比过滤数组更简单、更有效。

索引路径是swift 3中的结构,因此无法将索引作为引用进行比较。。。使用运算符,对于equalitySo
nsindepath
在Swift 2中是引用类型,但在Swift 3中变成了值类型?(除了被重命名为
indepath
?)@duncac No,
nsindepath
仍然存在
IndexPath
只是它的值类型包装器——请参阅。尽管“
indepath
现在是一个结构体”的措辞可能会丢失“现在”;)@DuncanC Swift仅将Obj-C
nsindepath
作为结构导入。对于
String
NSString
也一样。您仍然可以使用
as
轻松地将一个转换为另一个。对于Obj-C中不可变的许多类型也是如此。还要注意的是,表视图有时会重用
nsindepath
来节省内存,因此从表视图中保存和索引路径并比较引用从来都不安全,除非调用
copy
@duncac:Swift 3中有两个有时会混淆的更改:“具有值语义的覆盖类型”(SE-0069),例如NSIndexPath的IndexPath,以及“删除NS前缀”(SE-0086),例如NSBundle重命名为Bundle。我将切换到Set!
var selectedIndexPaths: Set<IndexPath> = []
selectedIndexPaths.insert(indexPath)
selectedIndexPaths.remove(indexPath)