swift - 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()'
解决方案
推荐阅读
- android - 使用 wowza 引擎进行实时流的 AR 面部过滤器
- python - 如何用硒选择一个[不断变化的]元素
- java - 在 ARcore 移动应用程序中显示 .png 或 .jpeg 图像?
- ios - Xcode 和 Swift UI 中是否存在导致不相关错误的已知错误?
- amazon-web-services - 调试 AWS HTTP API (beta) JWT Authorizer
- ios - 如何在包装器 Swift View 中使用自定义 UIView 的扩展功能?
- javascript - 自定义滚动条跨浏览器支持
- python - One-Hot-Encode only integers, slices(`:`), ellipsis(`...`), numpy.newaxis(`None`) and integer or boolean arrays are valid indicies problem
- amazon-web-services - 列出所有私有 IP,除了来自 awscli 的少数标签名称
- c++ - 如何从 C++ 程序中找到 STL 标头?