【发布时间】:2018-12-14 06:33:04
【问题描述】:
您好,我尝试为我的自定义异步数组创建 enumerate() 方法,但仍然出现编译错误。我的自定义类看起来像这样:
class AsyncArray<T> {
private var array = [T]()
private var queue = DispatchQueue(label: "async_queue", attributes: .concurrent)
func enumerated() -> EnumeratedSequence<[T]> {
var value = EnumeratedSequence<[T]>() // compilation error Cannot invoke initializer for type 'EnumeratedSequence<[T]>' with no arguments
queue.sync {
value = self.array.enumerated()
}
return value
}
}
如何在我的自定义类中实现enumerated() 方法?
【问题讨论】:
标签: arrays swift generics dispatch