The first element of List<T> with given are requirement
First element
Compile error: Ambiguous use of 'filter'
Let say I have such object
class Car: Object {
let similarCars = List<Car>()
}
let car = Car()
// similarCars are not empty
let talkWithThisId = car.similarCars.filter { $0.color == color }.first // Ambiguous use of 'filter'
This code worked just fine on swift 3.1/3.2
Realm framework version: 2.10.1
Xcode version: Xcode 9 GM, Swift 4
Dependency manager + version: Carthage 0.25.0
@icanswiftabit It seems probably Swift compiler issue. We will find the way to avoid it, in the meanwhile, the workaround is split it into two sentences using a temporaly variable instead method chain like the following.
let cars = car.similarCars.filter { $0.color == color }
let car = cars.first
Update: Xcode 9 and still the same issue
Here鈥檚 the relevant bug on bugs.swift.org:
have you tried to wrap the filter closure with round parentheses?
car.similarCars.filter ({ $0.color == color }).first
it usually works form me when I use the guard let statement.
Most helpful comment
@icanswiftabit It seems probably Swift compiler issue. We will find the way to avoid it, in the meanwhile, the workaround is split it into two sentences using a temporaly variable instead method chain like the following.