Reputation: 21
I have a Alert with Date Picker and i save the NSDate in CoreData. So when the NSDate is safety then it´s doesn´t show the Alert anymore. So i need a func from CoreData Attribute to request the Attribute is it nil or not nil. Have anything an idea how i can do that ?
Upvotes: 1
Views: 922
Reputation: 415
What you can do is add a predicate to your fetchRequest that checks whether values are nil as so:
let fetchRequest = NSFetchRequest(entityName: "entNameHere")
let predicate = NSPredicate(format: "%K != nil", "attributeNameHere")
fetchRequest.predicate = predicate
executing the request should you get you all entries where the attribute is not nil. Conversely you could use '== nil' to find those that are nil
Upvotes: 3
Reputation: 40030
To check if something is nil
you can do optional unwrapping. Let's assume you have a property called boDate
that is an optional and can be nil
if let boDate = boDate {
// property is not nil here
} else {
// property is nil
}
Upvotes: -1