Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 681
Ulli H Avatar asked May 21 '26 21:05

Ulli H


1 Answers

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

like image 115
Gargoyle Avatar answered May 23 '26 11:05

Gargoyle