1

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];
4

1 に答える 1

3

私は少し推測していますが (これを確認するためのテスト プロジェクトを作成していないため)、「右側」は定数値であり、キー パスではありません。だから交換すればいい

 [NSExpression expressionForKeyPath:@"Awaiting inputs"]

[NSExpression expressionForConstantValue:@"Awaiting inputs"]

NSArray *right=@[ ... ]、他の可能な値についても同様です。

于 2013-12-26T16:17:21.920 に答える