NSPredicate to compare Int32

匆匆过客 提交于 2019-12-24 01:18:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!