首页 > 解决方案 > Array 上的扩展,其中 Element 是通用的,未编译

问题描述

我想知道为什么会编译

extension Array where Element == Int {
    func newTest() {
        let array = [[1,2,3],[4,5,6],[7,8,9]]
        let j = Array(array.joined())
        let f = array.flatMap{$0}
    }
}

但这不会编译

struct Test<T> {}

extension Array where Element == Test<Int> {
    func newTestGeneric() {
        let array = [[1,2,3],[4,5,6],[7,8,9]]
        let j = Array(array.joined())
        let f = array.flatMap{$0}
    }
}

在这条线上 let j = Array(array.joined())

我收到一个错误: Ambiguous reference to member 'joined()'

标签: swift

解决方案


推荐阅读