NSPredicateEditor in Xcode 4

前端 未结 4 1081
醉梦人生
醉梦人生 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:10

    running into the same problem with XCode4, unfortunatly i can't test no more with Xcode3's IB.

    Starting with the sample found here http://nvie.com/posts/nspredicateeditor-tutorial/ i suspect XCode4 IB to have bugs, because adding a keypath in Predicate Editor via IB and adding an entry in the DEFAULT_PREDICATE leads to "Warning - unable to find template matching predicate".. Check this sample to understand ;) Seems there's known issue ? Maybe i'm missing something..

    0 讨论(0)
  • 2021-01-05 07:21

    It seems to be a bug in xCode 4 indeed. When you log the predicate formed by the predicateEditor, you'll see that it sounds

    "date" >= CAST(344464706.878616, "NSDate")

    instead of:

    date >= CAST(344464706.878616, "NSDate")

    The first style occurs in xCode 4 and the latter in xCode 3.

    0 讨论(0)
  • 2021-01-05 07:24

    I have the same issue with XCode 4 and NSPredicateEditor, so it's not just you. I was able to open my code in XCode 3, delete the bindings in IB and reassign the bindings and it worked normally. It has something to do with the way that XCode 4 is setting up the bindings – it appears to be buggy. Setting it programmatically is probably the best answer if XCode 3 is not an option.

    0 讨论(0)
  • 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]];
    
    0 讨论(0)
提交回复
热议问题