swift:获取最近存储在核心数据中的日期 [英] swift : get the closest date stored in the core data

查看:143
本文介绍了swift:获取最近存储在核心数据中的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个数据在核心数据。

I have two data in core data.


  • 实体名称=联系人,属性名称=日期日期),content(textFeild.text)

这是表视图中的一种信息,我想在另一个视图控制器中只显示一个内容。

It is that sort of information in a table view, was a success. I want to show only one content in the another view controller. The data of the closest time to the current time.

我被要求帮助下面的代码。

I was asked to help with the following code.

var stores: Contact?

if ((stores?.date!.timeIntervalsince1970 ?? 0) > NSDate().timeIntervalSince1970) {

    labelName.text = stores?.content!
    }

但标签上没有任何迹象。没有错误...问题是什么?

But the label has not been any indication on. And no error... What's the problem?

推荐答案

正如你提到的使用Core Data,正确的方向是获取这个对象(联系人)。然后你将有一个NSManagedObjects数组。如果fecth成功,你在一个'for in'循环中迭代它们。
在这个循环中使用'.valueForKey'提取日期并应用你创建的规则,返回你想要的NsManagedObject或者属性。

As you mentioned using Core Data, the right direction is to Fetch this objects (the contacts). Then you will have an Array of NSManagedObjects. If the fecth is successful you iterate them in a ´for in´ loop. Inside this loop use ´.valueForKey´ to extract the dates and apply the rules you have created, returning the NsManagedObject or Atribute you want.

这篇关于swift:获取最近存储在核心数据中的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆