ios - 用两个字符串过滤字典数组
<p><p>对于搜索下拉表,我需要分别在单元格文本标签和详细文本标签中显示“描述”和“搜索词”。我需要实现基于两个字符串的过滤器,即搜索文本应该与“描述”和“搜索词”进行比较。我试过 NSPredicate 但它只能过滤一个字符串 </p>
<pre><code>NSString *substring = ;
NSLog(@"substring %@",substring);
NSMutableArray *arr2Filt= ;
NSPredicate *predicate = %@",substring];
NSArray *filteredarr = ];
NSLog(@"filtered array %@",filteredarr);
</code></pre>
<p>我尝试修改这两个字符串,但我没有得到更好的灵魂。</p>
<pre><code>[{
Description = "Rental Jewellery, Jewellery for events";
ProfessionId = "<null>";
SKUFormat = "<null>";
SearchTerms = "Rental Jewellery";
SpecialityId = 62;
tokens = "<null>";
value = "<null>";
},
{
Description = "Kids Party with Food and Games Venues";
ProfessionId = "<null>";
SKUFormat = "<null>";
SearchTerms = "Party Venue";
SpecialityId = 63;
tokens = "<null>";
value = "<null>";
},
{
Description = "Music, Dance, Sports classes";
ProfessionId = "<null>";
SKUFormat = "<null>";
SearchTerms = Classes;
SpecialityId = 64;
tokens = "<null>";
value = "<null>";
},
{
Description = "Zumba, Yoga, Aerobics classes";
ProfessionId = "<null>";
SKUFormat = "<null>";
SearchTerms = "Fitness/Health";
SpecialityId = 65;
tokens = "<null>";
value = "<null>";
}
]
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>你可以这样做</p>
<pre><code>NSString *substring = ;
NSPredicate *predicate = %@ AND SearchTerms contains %@",substring, substring];
NSArray * filteredarr =[ copy];
NSLog(@"filtered array %@",filteredarr);
</code></pre></p>
<p style="font-size: 20px;">关于ios - 用两个字符串过滤字典数组,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/37630285/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/37630285/
</a>
</p>
页:
[1]