我正在尝试从 json 响应中过滤产品列表。对于左侧表达式“状态”右侧,我需要一个下拉菜单。所以我用了正确的表达方式。在使用 nspredicate 过滤此 json 时,由于空间原因,它无法正常工作。请帮助我实现这一目标。
NSArray *Mainarray;// Suppose this contains the response as "status"="Checked In" for 1 product and for other product "status"="Lost/Missing"
NSArray *left=@[[NSExpression expressionForKeyPath:@"status"]];
NSArray *right=@[[NSExpression expressionForKeyPath:@"Awaiting inputs"],[NSExpression expressionForKeyPath:@"Checked In"],[NSExpression expressionForKeyPath:@"Checked out"],[NSExpression expressionForKeyPath:@"Lost/Missing"],[NSExpression expressionForKeyPath:@"xxx Testing/Primary System"],[NSExpression expressionForKeyPath:@"Sold To"],[NSExpression expressionForKeyPath:@"closed"],[NSExpression expressionForKeyPath:@"Used for Parts"]];
NSArray *operators= @[@(NSEqualToPredicateOperatorType),@(NSNotEqualToPredicateOperatorType)];
NSArray *compoundTypes = @[@(NSAndPredicateType),@(NSOrPredicateType),@(NSNotPredicateType)];
NSPredicateEditorRowTemplate *template;
template=[[NSPredicateEditorRowTemplate alloc]initWithLeftExpressions:left rightExpressions:right modifier:NSDirectPredicateModifier operators:operators options:(NSCaseInsensitivePredicateOption | NSDiacriticInsensitivePredicateOption)];
compoundtemp = [[NSPredicateEditorRowTemplate alloc] initWithCompoundTypes:compoundTypes];
[predicateEditor setRowTemplates:@[template,compoundtemp]];
NSPredicate *predicate=[predicateEditor predicate];
NSArray *resultArray=[Mainarray filteredArrayUsingPredicate:predicate];