Xcode 9.1-对成员过滤器的引用过多 [英] Xcode 9.1 - Ambigous reference to member filter

查看:98
本文介绍了Xcode 9.1-对成员过滤器的引用过多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我过去已经遇到过这个问题,我已解决它.

I already experienced this issue in the past, I fixed it.

但是今天我刚刚下载了新的Xcode版本9.1,但我的App不再构建了,我得到了:

But today I just download the new Xcode version 9.1 and my App is not building anymore, I got :

对成员过滤器"的含糊不清

Ambiguous reference to member 'filter'

我不知道为什么,这不是我正在处理的代码.数周以来,该应用程序的构建/编译正常.

I don't know why, this is not the piece of code I was working on. The app is building/compiling fine since weeks.

当我查看 Apple官方网站,我似乎找不到与我的问题有关的任何信息.

When I check the Release Note on the Official Apple Website, I don't seem to find any reference to my issue.

这是两个小时前运行良好的代码:

So here is the piece of code that was working perfectly 2 hours ago :

var severeWeather: Results<SevereWeather>?
var vigiArray = Array<SevereWeather>()
var redCount: Int = 0

severeWeather = realm.objects(SevereWeather.self).filter(NSPredicate(format: "department != nil"))
.sorted(byKeyPath: "departmentNumber")

vigiArray = Array(severeWeather!)

redCount = vigiArray.filter { $0.dangerLevels.filter { $0.level.value == 4 }.count > 0 }.count

我的代码有什么问题?

推荐答案

RealmCollection也具有filter方法,该方法的实现方式不同.由于某些原因,Swift编译器不知道应引用哪个.

RealmCollection also has a filter method, which is implemented differently. For some reason, Swift compiler doesn't know which one it should refer.

那呢:

redCount = vigiArray.filter {
    return $0.dangerLevels.filter(NSPredicate(format: "%K == %@", "level.value", NSNumber(integerLiteral: 4))).count > 0
}.count

构建谓词,让领域为您完成工作,而不是自己访问dangerLevels中的每个元素.

Instead of accessing each element in dangerLevels yourself, build Predicate and let realm do the job for you.

用此替换您的嵌套过滤器,它应该可以正常编译.

Replace your nest filter with this and it should be compiling just fine.

这篇关于Xcode 9.1-对成员过滤器的引用过多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆