UlliHeinelt UlliHeinelt - 1 year ago 164
iOS Question

can´t understand fetchRequest.predicate

I´ve a quite "simple" predicate for a NSFetchRequest:

guard let kategorie = self.fetchedResultsController.objectAtIndexPath(indexPath) as? Kategorien else {
let fetchRequest = NSFetchRequest(entityName: "Details")
fetchRequest.predicate = NSPredicate(format: "kategorie == %i", kategorie.katid!)
do {
let results = try self.managedObjectContext.executeFetchRequest(fetchRequest) as! [Details]

The content of the sqllite-"table" is
enter image description here

the content of the variables are

enter image description here

So from

fetchRequest.predicate = NSPredicate(format: "kategorie == %i", kategorie.katid!)

i get the Predicate

kategorie == 18


kategorie.katid is 1

I can´t understand it :-(

Any help???

Answer Source

That's really strange, but you can just do:

NSPredicate(format: "kategorie = \(kategorie.katid!)")

And then you don't need to worry about whether you need a %i, or a %ld, or a %@, etc...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download