Swift Array.filter() returning Iterable<> that can't be assigned to array

Hi there, we are having this problem on Fire 8.3.91.1965 when compiling to java:

public class Foo
{
    let name: String
    
    public init(name: String)
    {
        self.name = name
    }
}

public class X
{
    static public func getFiltered(items: [Foo], name: String) -> [Foo]
    {
        // error E62: Type mismatch, cannot assign "Iterable<Foo>" to "swift.Array<Foo>"
        // appending .toSwiftArray() fixes in Fire but this but won't work in Xcode
        return items.filter { $0.name == name }
    }
}

print("Hi")

Since iteration works on Iterables you can work around it like this but it’s pretty clunky:

public class X
{
    static public func getFiltered(items: [Foo], name: String) -> [Foo]
    {
        let filtered = items.filter { $0.name == name }
        var x: [Foo] = []
        for f in filtered
        {
            x.append(f)
        }
        return x
    }
}

It’s a little odd how apple converts it straight to an array but there we go. What do you reckon?

Any thoughts on this one? In case it helps, here’s a sample project with the compilation error: FilterIssue.zip (326.7 KB)

As designed. We purposely return sequences, not arrays, consistently. The Apple Swift Base Library, honestly, looks like it was designed by someone who has no clue how to design a proper API, and no understanding of how concepts such as protocols work.

You can call .array (I believe — don’t have the code in front of me right now) to turn it into an array.

I discovered today that apple swift is actually is working a bit better here than you give it credit for.
Despite .filter() returning an array, and looking like its pretty non-functional, the return type is a LazyFilterCollection under the hood until its accessed.

Having to add .toSwiftArray causes us much grief in trying to write compatible code.