NSPredicateEditor in Xcode 4

前端 未结 4 1083
醉梦人生
醉梦人生 2021-01-05 06:40

Bit of an issue with Xcode 4\'s predicate editor controls - I think I\'m doing everything right, and it really seems like the IDE itself is busted.

I\'m having this i

4条回答
  •  悲哀的现实
    2021-01-05 07:25

    I know this isn't the answer you want to hear, but I highly recommend setting up the the predicate editor programmatically. Setting it up in IB, in my experience, isn't very intuitive. At least in code you can explicitly see what's going on.

    NSArray *keyPaths = @[[NSExpression expressionForKeyPath:@"title"],
                          [NSExpression expressionForKeyPath:@"writer"]];
    NSArray *operators = @[@(NSEqualToPredicateOperatorType),
                           @(NSNotEqualToPredicateOperatorType),
                           @(NSBeginsWithPredicateOperatorType),
                           @(NSEndsWithPredicateOperatorType),
                           @(NSContainsPredicateOperatorType)];
    
    NSPredicateEditorRowTemplate *template = [[NSPredicateEditorRowTemplate alloc] initWithLeftExpressions:keyPaths
                                                                              rightExpressionAttributeType:NSStringAttributeType
                                                                                                  modifier:NSDirectPredicateModifier 
                                                                                                 operators:operators 
                                                                                                   options:(NSCaseInsensitivePredicateOption | NSDiacriticInsensitivePredicateOption)];
    
    NSArray *compoundTypes = @[@(NSNotPredicateType),
                               @(NSAndPredicateType),
                               @(NSOrPredicateType)];
    NSPredicateEditorRowTemplate *compound = [[NSPredicateEditorRowTemplate alloc] initWithCompoundTypes:compoundTypes];
    
    [myPredicateEditor setRowTemplates:@[template, compound]];
    

提交回复
热议问题