Swi*_*ude 3 cocoa nsdictionary nsarray nspredicate
我正在尝试使用谓词从NSMutableArray中获取NSDictionary:
NSMutableArray *arr = [NSMutableArray arrayWithArray:[self createArrayFromCSV:savedCSV withDelimiter:delim firstLineContainsKeys:YES]];
// The method «createArrayFromCSV returns an array of dictionaries
NSLog(@"Array %@", [arr objectAtIndex:0]); // works fine
// spits out:
// Array {
// product = "MyProduct";
// "id_product" = 29;
// }
// idField and idVal are passed to the method
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(%@ == %@)", idField, idVal];
NSLog(@"predicate %@", predicate);
// spits out predicate "id_product" == "29"
NSArray *filtered = [arr filteredArrayUsingPredicate:predicate];
NSLog(@"Filtered %@", filtered);
// Filtered is always empty
Run Code Online (Sandbox Code Playgroud)
什么想法我做错了???
[求助]显然,我使格式字符串错了.这有效:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(%K == %@)", idField, idVal];
Run Code Online (Sandbox Code Playgroud)
根据这篇文章,NSPredicate predicateWithFormat传递属性名称
对于密钥或密钥路径,必须使用@K
显然,我使格式字符串错误.这有效:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(%K == %@)", idField, idVal];
Run Code Online (Sandbox Code Playgroud)
根据这篇文章,NSPredicate predicateWithFormat传递属性名称
对于密钥或密钥路径,必须使用@K
| 归档时间: |
|
| 查看次数: |
3603 次 |
| 最近记录: |