You need to tell Swift what type of return should be through some call context:
Note that in the latter case, this would be necessary only if someCall used an undefined type of type Any as an argument. If instead someCall specified to take [Int] as an argument, the function itself provides a context, and you can simply write someCall( jList.toNSArray() )
In fact, sometimes the context can be very subtly deduced! This works for example:
extension Array { func asT<T>() -> [T] { var results: [T] = [] for x in self { if let y = x as? T { results.append(y) } } return results } } let a: [Any] = [1,2,3, "heffalump"]
source share