Realm-cocoa: Ambiguous use of 'filter' when filter the `List<T>`

Created on 19 Sep 2017  路  4Comments  路  Source: realm/realm-cocoa

Goals


The first element of List<T> with given are requirement

Expected Results

First element

Actual Results


Compile error: Ambiguous use of 'filter'

Steps to Reproduce

Code Sample

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

Version of Realm and Tooling


Realm framework version: 2.10.1

Xcode version: Xcode 9 GM, Swift 4

Dependency manager + version: Carthage 0.25.0

O-Community T-Bug

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.

let cars = car.similarCars.filter { $0.color == color }
let car = cars.first

All 4 comments

@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:

https://bugs.swift.org/browse/SR-1996

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.

Was this page helpful?
0 / 5 - 0 ratings