【发布时间】:2020-06-28 04:02:48
【问题描述】:
从 Realm 查询和排序后:
// fetch all Items sorted by Type
let results = realm.objects(Paper.self).sorted(byKeyPath: "Type", ascending: false)
var paperCollatedByType: [String : [Paper]] {
Dictionary(grouping: results, by: { $0.type })
}
// pulls out the keys from the dictionary made above, sorted
var uniqueType: [String] {
paperCollatedByDate.map({ $0.key }).sorted()
}
这是我制作列表的来源:
["kyasutoYellowSeparator": [Paper {
type = kyasutoYellowSeparator;
width = 111;
rollLength = 600;
quantity = 1;
importDate = 2020-06-28 12:11:19 +0000;
totalLength = 600;
isSlitted = 1;
}, Paper {
type = kyasutoYellowSeparator;
width = 12;
rollLength = 600;
quantity = 1;
importDate = 2020-06-28 03:18:22 +0000;
totalLength = 600;
isSlitted = 0;
}]]
我正在考虑创建一个按类型“kyasutoYellowSeparator”分组的列表:
List {
ForEach(paperCollatedByDate, id: \.self) { (section: [Paper]) in
Section(header: Text(section[0].type)) {
ForEach(section, id: \.self) { paper in
Text(paper.type)
}
}
}//end of list
但它完全失败了,请帮助我制作列表。感谢您花时间阅读我的问题。
【问题讨论】: