我正在尝试从 Magical Records 获取最新添加的数据
I am trying to fetch latest added data from Magical Records
我正在尝试从 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
})
我正在尝试从 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
})