How do I set up a NSPredicate to look for objects that have a nil attribute

后端 未结 4 1477
伪装坚强ぢ
伪装坚强ぢ 2020-12-01 23:29

I have a ManagedObject class, and one of the members of the class is a NSDate. I would like to display all objects of the class for which the date

4条回答
  •  不思量自难忘°
    2020-12-01 23:51

    Figured it out. Couldn't do it by using a predicate with a string format, so tried a predicate with a template and it worked. Here's the code that gave me objects that had endDate set to NULL:

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"endDate = $DATE"];
    predicate = [predicate predicateWithSubstitutionVariables:
                       [NSDictionary  dictionaryWithObject:[NSNull null] forKey: @"DATE"]];
    

提交回复
热议问题