核心数据 NSPredicate 转换键值
我有一个数据模型,其中包含 id 类型的值,我计划在需要时进行适当的转换。
我是否可以将它们转换为字符串并使用 NSPredicate 将它们与 UISearchBar 中的字符串进行比较,还是必须使用其他方法?
也许是这样的:
NSPredicate * predicate;
predicate = [NSPredicate predicateWithFormat:@"CAST(%K) contains[cd] %@", employeeID , theSearchBar.text];
I have a data model which has values of type id that I was planning on casting appropriately when needed.
Is it possible for me to cast these as strings and compare them to strings from a UISearchBar using NSPredicate or do I have to use another method?
Maybe something like this:
NSPredicate * predicate;
predicate = [NSPredicate predicateWithFormat:@"CAST(%K) contains[cd] %@", employeeID , theSearchBar.text];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不可以。
CAST()
函数不是这样工作的。我认为您只需假设从-employeeID
返回的id
与字符串相当。No. The
CAST()
function doesn't work that way. I think you just have to assume that theid
returned from-employeeID
is comparable to a string.