core-data NSDate搜索独特的天数和排序 [英] core-data NSDate searching for unique days and sorting

查看:91
本文介绍了core-data NSDate搜索独特的天数和排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于NSDates有关该地方的大量信息,但我还没有找到一个明确的解决方案。



我有一个事件实体,每个实体具有潜在的许多 EventSessionTime



事件< --- >> EventSessionTime



在1表视图中我想显示一个唯一的日期列表,在 Events 想要显示特定日期的活动(按时间排序)。



为了实现这一点,我目前有2个NSDates - 一天一次和一些过于复杂的搜索/排序。



1)找到这些信息



2)查找特定日期的所有活动(此处重复此处)




$ b

感谢。

解决方案

我现在有以下关系。仍然有冗余的日期信息..



事件< --- >> EventSessionTime < < - > EventDay



UNIQUE days with events,no concern about specific time



我可以创建特定的日期,我知道时间。

  ... 
[NSEntityDescription entityForName:@ EventSessionTimeinManagedObjectContext:self.managedObjectContext];
...
NSArray * res = [managedObjectContext executeFetchRequest:fetchRequest error:& error];
[self myResultArray:[res valueForKeyPath:@@ distinctUnionOfObjects.eventDay.day]];

您可以推断我的属性和关系名称。



2)在特定日期查找所有活动(此处重复)



我使用以下谓词查找指定日期。它不会返回重复项(SUBQUERY(eventTime,$ x,$ x.eventDay.day =$))

  [NSPredicate predicateWithFormat: =%@)。@ count> 0),<从上一个列表中选择的日期>]; 


Lots of information on NSDates about the place, but I haven't found a clear solution to this.

I have a list of Event entities, each with potentially many EventSessionTimes.

Event <--->> EventSessionTime

In 1 table view I want to display a unique list of days that have Events, in another table view I want to show the events on a particular day (ordered by time).

To achieve this I currently have 2 NSDates - a day and time - and some overly complicated searching/sorting. I want to remove this redundant information.

With that in mind, how can I:

1) Finding all UNIQUE days with events, no concern about specific time

2) Finding all EVENTS on a particular day (duplicates fine here)

Any tips on how to better achieve this would be great.

Thanks.

解决方案

I now have the following relationship. Still have redundant date information..

Event <--->> EventSessionTime <<--> EventDay

1) Finding all UNIQUE days with events, no concern about specific time

I can create specific dates where I know the time. The localised nature of my application means I can do this safely.

...
[NSEntityDescription entityForName:@"EventSessionTime" inManagedObjectContext:self.managedObjectContext];
...
NSArray *res = [managedObjectContext executeFetchRequest:fetchRequest error:&error];
[self myResultArray:[res valueForKeyPath:@"@distinctUnionOfObjects.eventDay.day"]];

You can infer my attribute and relationship names.

2) Finding all EVENTS on a particular day (duplicates fine here)

I use the following predicate to find all events on the specified day with. It does not return duplicates

[NSPredicate predicateWithFormat: @"(SUBQUERY(eventTime, $x, $x.eventDay.day == %@).@count > 0)", <the day selected from the previous list>];

这篇关于core-data NSDate搜索独特的天数和排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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