简体   繁体   English

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

[英]I am trying to fetch latest added data from Magical Records

I am trying to fetch latest added data from Magical Records. 我正在尝试从Magical Records获取最新添加的数据。 I have one entity called weighttrack and it has two attributes- weight and date and I want to fetch latest added dates weight to my label so how could it possible? 我有一个名为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)
    }
}

You can do it with Filter 你可以使用Filter做到这一点

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我正在尝试从ios Swift项目中的Firestore数据库中获取数据 - I am trying to fetch data from Firestore database in my ios Swift Project 如何使用神奇的Records Library Swift获取属性中的所有值 - how to fetch all values in attributes using magical Records Library Swift 我正在从ios 10中的核心数据获取记录,但未获得iOS 9的相同记录 - I am getting records from core data in ios 10 but I am not getting same records for iOS 9 我正在尝试为 iOS 获取 Chromium,但卡在 fetch iOS 命令中 - I am trying to fetch Chromium for iOS, but stuck in fetch iOS command 我正在尝试从本地标识符中获取资产并在collectionview中显示图像,但这会使滚动变得混乱 - I am trying to fetch asset from local identifier and displaying images in collectionview but it makes scroll jerkiness 我正在尝试从URL提取图像并将其作为应用程序中联系人的缩略图 - I am trying to fetch image from a URL and make it as a thumbnail for my contacts in my application 如何将数据添加到数据库后立即从Core Data获取数据 - how to fetch data from Core Data as soon as it is added to database 我尝试通过WCF服务从SQL Server提取数据 - I am try to fetch the data from sql server through WCF service 尝试从ios应用中获取google +个人资料图片时,为什么会收到错误代码403? - Why am I getting error code 403 while trying to fetch google+ profile image from my ios app? 我正在尝试从 json 文件中提取数据并将该数据写入变量 - I am trying to extract data from a json file and write that data into variables
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM