DEV
DEV

Reputation: 949

NSPredicate to compare Int32

elementFetch.predicate = NSPredicate(format: "pageId = %@",(Int32(pagesFromDb.first?.pageId)) !)
var Data = try moc.fetch(elementFetch as! NSFetchRequest<NSFetchRequestResult>) as! [Element]

I tried it with %I, %d, and converting to Int or number, nothing works. Please suggest how to do this.

Upvotes: 5

Views: 1897

Answers (1)

fdelafuente
fdelafuente

Reputation: 1122

This is because you are using the operator %@ which is for Strings. For integers use %i (not %I) as follows:

elementFetch.predicate = NSPredicate(format: "pageId = %i", pagesFromDb.first?.pageId)

Upvotes: 6

Related Questions