gpt4 book ai didi

ios - 包含 NSDictionary 的数组上的快速枚举循环

转载 作者:行者123 更新时间:2023-11-29 03:57:21 24 4
gpt4 key购买 nike

我有一个包含字典的数组,我必须在这个数组上实现搜索功能并让它只显示在搜索栏中输入的文本......................... ......

我已经尝试过这段代码

-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
if (searchText.length == 0) {
isFiltered = NO;
}
else {
isFiltered = YES;

FilteredData = [[NSMutableArray alloc]initWithArray:[ParsedData valueForKey:@"FolderName"]];
NSMutableArray *searchData = [NSMutableArray new];
for(NSDictionary *dict in ParsedData){

NSDictionary *tempDict= @{@"FolderName":dict[@"FolderName"],@"ID":dict[@"ID"]}
[searchData addObject:tempDict];

SearchData = [[NSMutableArray alloc]initWithArray:searchData];
NSLog(@"DATA %@",SearchData);

}

//Fast Enumeration

for (NSString *fileName in FilteredData)
{
NSRange fileNameRange = [fileName rangeOfString:searchText options:NSCaseInsensitiveSearch];

if (fileNameRange.location == NSNotFound) {

[SearchData removeObject:[SearchData valueForKey:@"FolderName"]];

}
}

}

[listingSet reloadData];
}




This is the data present in parsed data as below plz check out.parse data array is getting data from an xml


2013-05-02 15:14:19.935 DocumentManagement[423:207] PARSED DATA (
{
CreatedBy = 1;
FolderName = Posteingang;
ID = 13000;
ParentID = 0;
},
{
CreatedBy = 1;
FolderName = "my folder";
ID = 13183;
ParentID = 0;
},

最佳答案

据我了解,您有一个字典数组存储在 parseData 数组中。您想要形成一个与值 FolderName 和 searchText 相匹配的子数组。

您可以使用NSPredicate来做到这一点

-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
if (searchText.length == 0) {
isFiltered = NO;
}
else {
isFiltered = YES;

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"FolderName LIKE [cd] %@",searchText];
searchData = [[parsedData filteredArrayUsingPredicate:predicate]mutableCopy];
}

[listingSet reloadData];
}

关于ios - 包含 NSDictionary 的数组上的快速枚举循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16335081/

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