我正在尝试在表格视图中过滤Firebase数据,以将彼此具有相同类别(子值)的项目分组。当前,它不基于子值返回值。我认为这是随机执行的。
这是我的代码:
我如何尝试过滤数据:
def isSiete(num):
return extract_digit(num, 2) == 7
型号:
self.items.append(item)
self.items.sort(by: { (item1, item2) -> Bool in
return item1.category.compare(item2.category) == .orderedSame
})
self.tableView.reloadData()
获取功能:
struct Item {
var id: String?
var user: User
var fromId: String?
let item: String
let category: String
let creationDate: Date
init(user: User, dictionary: [String: Any]) {
self.user = user
self.item = dictionary["item"] as? String ?? ""
self.fromId = dictionary["fromId"] as? String ?? ""
self.category = dictionary["category"] as? String ?? ""
let secondsFrom1970 = dictionary["creationDate"] as? Double ?? 0
self.creationDate = Date(timeIntervalSince1970: secondsFrom1970)
}
}
数据库: