这是这个问题的后续行动:
在那里我使用以下代码将Records 数组转换为s数组Person:
let records = // load file from bundle
let persons = records.flatMap(Person.init)
Run Code Online (Sandbox Code Playgroud)
由于此转换可能需要一些时间来处理大文件,因此我希望监控索引以提供进度指示器.
这种flatMap结构有可能吗?我想到的一种可能性是在init函数中发送通知,但我在想从内部计算记录也是可能的flatMap?
Ale*_*ica 14
对!使用enumerated().
let records = // load file from bundle
let persons = records.enumerated().flatMap { index, record in
print(index)
return Person(record)
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2089 次 |
| 最近记录: |