Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
810 views
in Technique[技术] by (71.8m points)

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

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 is NOT set. I tried using a predicate like this:

NSPredicate *predicate = [NSPredicate predicateWithFormat: @"(date = NIL)"];

But I still get objects where the date is set. What is the right way to set up a predicate for this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I think it's a case sensitivity issue. You can use "nil" or "NULL", but not "NIL". This works fine for me:

NSPredicate *eventWithNoEndDate = [NSPredicate predicateWithFormat:@"endDate = nil"];

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...