生成此字符串的最佳方法是什么? (NSMutableString...)
我有一个字典,其键是 NSStrings,其对象是 NSArray。举个例子:
key (NSString) : GroupA
value (NSArray): John
Alex
Joe
Bob
类似这样的条目还有很多,这只是一个例子。我需要做的是生成一个像这样的字符串(例如:
(GroupA contains[cd] ('John' OR 'Alex' OR 'Joe' OR 'Bob')) AND (GroupB contains[cd] ('Starcraft' OR 'WOW' OR 'Warcraft' OR 'Diablo')) AND .....
我将把这个字符串提供给 NSPredicate。生成这个字符串的最佳方法是什么?我可以使用 for 循环和 if 等等,但是有吗?更优雅的方式? 谢谢。
I have a dictionary whose keys are NSStrings and whose objects are NSArray. Here's an example:
key (NSString) : GroupA
value (NSArray): John
Alex
Joe
Bob
There are many entries like this, this is just an example. What I need to do is generate a string like this (for example:
(GroupA contains[cd] ('John' OR 'Alex' OR 'Joe' OR 'Bob')) AND (GroupB contains[cd] ('Starcraft' OR 'WOW' OR 'Warcraft' OR 'Diablo')) AND .....
I am going to be feeding this string to an NSPredicate. What's the best way to generate this string? I can use for loops and if and all that, but is there a much more elegant way?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这不是一个有效的谓词格式字符串,因此即使您最终生成了它,您也无法将其转换为
NSPredicate
这就是您想要的:
这没有这种情况 -以及您的原文所暗示的变音符号不敏感。如果你真的需要它,那么你需要变得更复杂一些:
That's not a valid predicate format string, so even if you end up generating it, you won't be able to convert it into an
NSPredicate
Here's what you want instead:
This doesn't have the case- and diacritic-insensitivity that your original was implying. If you really need that, then you're going to need to get a bit more complicated:
应该是这样的
It should be something like this