【发布时间】:2020-08-18 18:17:07
【问题描述】:
我正在将通过完成块获取的项目的列表转换为 SwiftUI 列表。这是我目前正在使用的:
struct MoreView: View {
private let seasonArray = [Season]()
var body: some View {
List {
ForEach(seasonArray, id:\.self) { season in
Text(season.name)
}
}
}
private mutating func fetchSeasons() {
ContentManager().getSeasons() { response in
seasonArray = response.sorted { $0.year < $1.year }
// Reloaded tableview in UIKit here
}
}
}
在fetchSeasons() 运行并返回后,使用seasonArray 变量填充列表的最佳做法是什么?
【问题讨论】:
标签: list foreach swiftui completion