问题
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.
回答1:
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)
来源:https://stackoverflow.com/questions/41274279/nspredicate-to-compare-int32