gpt4 book ai didi

swift - 我正在尝试从 Magical Records 获取最新添加的数据

转载 作者:行者123 更新时间:2023-11-30 10:46:13 25 4
gpt4 key购买 nike

我正在尝试从 Magical Records 获取最新添加的数据。我有一个名为 Weighttrack 的实体,它有两个属性 - 重量和日期,我想将最新添加的日期重量获取到我的标签,那么这怎么可能呢?

class WTStatusVC: UIViewController {
var WeightArray = [WeightTracker]()
var tsk: WeightTracker?
@IBOutlet weak var currentWeightLbl: UILabel!
@IBOutlet weak var previousWeightLbl: UILabel!

override func viewWillAppear(_ animated: Bool) {
super .viewWillAppear(animated)

if let data = WeightTracker.mr_findAll(with: NSPredicate(format: "date == %@", "\(String(describing: tsk?.date))")) as? [WeightTracker] {

WeightArray = data
DispatchQueue.main.async {
self.currentWeightLbl.text = self.tsk?.weight
}
print(data)
}
}

最佳答案

你可以用过滤器来做到这一点

self.WeightArray = self.WeightArray.filter({ (item) -> Bool in
return item.date == tsk?.date
})

关于swift - 我正在尝试从 Magical Records 获取最新添加的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55724484/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com