【问题标题】:How to resolve space problems while using nspredicate in objective c?在目标 c 中使用 nspredicate 时如何解决空间问题?
【发布时间】:2013-12-26 15:42:33
【问题描述】:

我正在尝试从 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];

【问题讨论】:

    标签: objective-c cocoa nspredicate nspredicateeditor


    【解决方案1】:

    我有点猜测(因为我没有建立一个测试项目来验证这一点), 但“右手边”是常数值而不是关键路径。 所以你应该替换

     [NSExpression expressionForKeyPath:@"Awaiting inputs"]
    

    通过

    [NSExpression expressionForConstantValue:@"Awaiting inputs"]
    

    NSArray *right=@[ ... ] 中,对于其他可能的值也是如此。

    【讨论】:

      猜你喜欢
      • 2021-01-14
      • 1970-01-01
      • 2012-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多