Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/107.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 核心数据谓词:活动日期为NSDate的所有组?_Iphone_Ios_Core Data_Nsdate_Fetch - Fatal编程技术网

Iphone 核心数据谓词:活动日期为NSDate的所有组?

Iphone 核心数据谓词:活动日期为NSDate的所有组?,iphone,ios,core-data,nsdate,fetch,Iphone,Ios,Core Data,Nsdate,Fetch,我有以下数据模型: Group(name, color, activities*) // one group may have many activities Activity(startTime, endTime, location, Group*) // startTime and endTime are NSDate, group is an inverse relationship 所以,如果我想得到所有至少有一个活动在指定日期(比如时间)的组,我应该构造什么谓词 我的想法: 首先获得

我有以下数据模型:

Group(name, color, activities*) // one group may have many activities
Activity(startTime, endTime, location, Group*) // startTime and endTime are NSDate, group is an inverse relationship
所以,如果我想得到所有至少有一个活动在指定日期(比如时间)的组,我应该构造什么谓词

我的想法:

  • 首先获得所有活动
  • 然后将它们的组放入一个集合中,以删除重复的组
  • 将集合转换为数组
  • 因此:

    所以我得到了一系列独特的群组,它们在时间上至少有一个活动

    有没有其他方法可以在不进行后期处理的情况下进行提取

    谢谢

    编辑:

    我可以做:

    [NSPredicate predicateWithFormat:@"%@ >= activities.startTime AND %@ <= activities.endTime", theTime]
    

    [NSPredicate predicateWithFormat:@“%@>=activities.startTime和%@如果我很理解你的问题,可以

    您可以对
    而不是
    活动
    实体执行此操作。通过这种方式,您可以避免先获取
    活动
    的子实体,然后应用筛选器。由于
    活动
    不是标量值,因此需要谓词修饰符(
    任何
    所有
    ,等等)或子查询

    关于你的问题,我将做以下几点:

    [NSPredicate predicateWithFormat:@"(SUBQUERY(activities, $x, $x.startTime >= %@ and $x.endTime <= %@).@count > 0)", theStartTime, theEndTime];
    
    [NSPredicate谓词格式:@”(子查询(活动,$x,$x.startTime>=%@和$x.endTime 0)”,开始时间,结束时间];
    
    关于谓词,我假设您希望找到包含在特定范围内的
    活动的
    s

    试着让我知道。希望这有帮助

    [NSPredicate predicateWithFormat:@"%@ >= activities.startTime AND %@ <= activities.endTime", theTime]
    
    [NSPredicate predicateWithFormat:@"(SUBQUERY(activities, $x, $x.startTime >= %@ and $x.endTime <= %@).@count > 0)", theStartTime, theEndTime];