gpt4 book ai didi

ios - NSPredicate完全匹配

转载 作者:行者123 更新时间:2023-12-01 18:44:12 25 4
gpt4 key购买 nike

 NSArray *arrData = [NSArray arrayWithObjects:
@"cloud,country,plant",
@"country,cloud,plant",
@"country,plant,cloud",
@"clouds,country,plant"
,@"country,clouds,plant",
nil];

从NSArray上方,我希望对象具有单词“cloud”

我尝试下面的代码
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(self beginswith %@ OR self contains[CD] %@)",@"cloud",@",cloud"];
NSArray *arrResult = [arrData filteredArrayUsingPredicate:predicate];

但是它在arrResult中提供了所有5个对象。但是我只需要3(0,1,2)个对象。

最佳答案

尝试:

 NSPredicate* predicate = [NSPredicate predicateWithBlock:^(NSString* string, NSDictionary* options){

NSArray* array = [string componentsSeparatedByString:@","];

return [array containsObject:@"cloud"];

}];

关于ios - NSPredicate完全匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37919934/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com