UlliHeinelt UlliHeinelt - 6 months ago 24
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 {
return
}
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


while


kategorie.katid is 1


I can´t understand it :-(

Any help???

Answer

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...