I try to return objects (Measure) where property rawValue
is not nil. My predicate is:
myPredicate = NSPredicate(format: "rawValue != %@", "nil")
And my request
let fetchRequest = NSFetchRequest(entityName:"Measure")
fetchRequest.predicate = predicate
do {
let fetchResults = try managedObjectContext?.executeFetchRequest(fetchRequest) as? [Measure]
if fetchResults!.count > 0{
measuresFetched = fetchResults!
}
} catch let error as NSError {
print("Fetch failed: \(error.localizedDescription)")
}
The problem is that my query is not returning objects with rawValue
= 0. And for me 0 is not nil.
My objects looks like below
class Measure: NSManagedObject{
@NSManaged var rawValue: NSNumber?
@NSManaged var date: NSDate
class func createInManagedObjectContext(moc: NSManagedObjectContext,rawValue: Double?, date: NSDate) -> Measure {
let newItem = NSEntityDescription.insertNewObjectForEntityForName("Measure", inManagedObjectContext: moc) as! Measure
newItem.rawValue = rawValue
newItem.date = date
return newItem
}
}
How can I return all objects where rawValue is not nil ?
try predicate like this
myPredicate = NSPredicate(format: "rawValue != nil")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With