NSPredicateEditor

  • I'm using the NSPredicateEditor template in IB, and it works well.
    The exception is with a BOOL value.  For example, if I have a BOOL
    value called flag, and I want to use the string (flag == 1), however,
    using the NSPredicateEditor always produces the string (flag == "1")
    which doesn't work.  Is there an option to create the string without
    the quotes?  Or is there some setting in NSPredicateEditor I'm not
    aware of?
    TIA.
  • On Jan 7, 2008, at 3:34 PM, Kimo wrote:

    > I'm using the NSPredicateEditor template in IB, and it works well.
    > The exception is with a BOOL value.  For example, if I have a BOOL
    > value called flag, and I want to use the string (flag == 1),
    > however, using the NSPredicateEditor always produces the string
    > (flag == "1") which doesn't work.  Is there an option to create the
    > string without the quotes?  Or is there some setting in
    > NSPredicateEditor I'm not aware of?
    > TIA.

    Hi Kimo,

    If you want to have the boolean option be represented by a text
    field, you can of course just select the Numbers type for the right
    expression.  That will coerce the right expressions to a numeric type
    and give you a string like flag == 1.

    If (more likely) you want the boolean value to be represented by a
    popup, this can't yet be configured in IB, but it is easy to do
    programmatically.  Create an NSPredicateEditorRowTemplate with left
    expressions your key path expressions, and right expressions as
    constant expressions containing your boolean values.  Then you can
    configure the view titles and all the rest by modifying the
    templateViews.

    Let me know if you have any questions,
    -Peter
  • On Jan 7, 2008, at 4:08 PM, Peter Ammon wrote:
    >
    > On Jan 7, 2008, at 3:34 PM, Kimo wrote:
    >
    >> I'm using the NSPredicateEditor template in IB, and it works well.
    >> The exception is with a BOOL value.  For example, if I have a BOOL
    >> value called flag, and I want to use the string (flag == 1),
    >> however, using the NSPredicateEditor always produces the string
    >> (flag == "1") which doesn't work.  Is there an option to create the
    >> string without the quotes?  Or is there some setting in
    >> NSPredicateEditor I'm not aware of?
    >> TIA.
    >
    > Hi Kimo,
    >
    > If you want to have the boolean option be represented by a text
    > field, you can of course just select the Numbers type for the right
    > expression.  That will coerce the right expressions to a numeric
    > type and give you a string like flag == 1.
    >
    > If (more likely) you want the boolean value to be represented by a
    > popup, this can't yet be configured in IB, but it is easy to do
    > programmatically.  Create an NSPredicateEditorRowTemplate with left
    > expressions your key path expressions, and right expressions as
    > constant expressions containing your boolean values.  Then you can
    > configure the view titles and all the rest by modifying the
    > templateViews.
    >
    > Let me know if you have any questions,
    > -Peter
    >

    Hi Peter,

    That helped a lot, thank you.  I have another question.  I created
    (programmatically) a NSPredicateEditorRowTemplate so that the left
    popup button has "Start Date" and "End Date."  The middle popup button
    has "is today" and "is the date" and "is before the date."  The right
    expression is a NSDatePicker.  However, when the user selects the
    operator "is today" I want the NSDatePicker to be hidden, and then
    visible for the other two operators.

    I see other apps do this (Mail for example), but I can't seem to
    accomplish the same thing.  I subclassed NSPredicateEditorRowTemplate
    so I could alter the templateViews, but I can't seem to determine
    which middle popup is selected.  What is the best way to hide the
    NSDatePicker when the user selects the menu item "is today" and then
    displays it for the other menu items?

    Thanks in advance!
    -Kimo
  • On Jan 24, 2008, at 12:47 PM, Kimo wrote:

    >
    > On Jan 7, 2008, at 4:08 PM, Peter Ammon wrote:
    >>
    >> On Jan 7, 2008, at 3:34 PM, Kimo wrote:
    >>
    >>> I'm using the NSPredicateEditor template in IB, and it works
    >>> well.  The exception is with a BOOL value.  For example, if I
    >>> have a BOOL value called flag, and I want to use the string (flag
    >>> == 1), however, using the NSPredicateEditor always produces the
    >>> string (flag == "1") which doesn't work.  Is there an option to
    >>> create the string without the quotes?  Or is there some setting
    >>> in NSPredicateEditor I'm not aware of?
    >>> TIA.
    >>
    >> Hi Kimo,
    >>
    >> If you want to have the boolean option be represented by a text
    >> field, you can of course just select the Numbers type for the
    >> right expression.  That will coerce the right expressions to a
    >> numeric type and give you a string like flag == 1.
    >>
    >> If (more likely) you want the boolean value to be represented by a
    >> popup, this can't yet be configured in IB, but it is easy to do
    >> programmatically.  Create an NSPredicateEditorRowTemplate with
    >> left expressions your key path expressions, and right expressions
    >> as constant expressions containing your boolean values.  Then you
    >> can configure the view titles and all the rest by modifying the
    >> templateViews.
    >>
    >> Let me know if you have any questions,
    >> -Peter
    >>
    >
    > Hi Peter,
    >
    > That helped a lot, thank you.  I have another question.  I created
    > (programmatically) a NSPredicateEditorRowTemplate so that the left
    > popup button has "Start Date" and "End Date."  The middle popup
    > button has "is today" and "is the date" and "is before the date."
    > The right expression is a NSDatePicker.  However, when the user
    > selects the operator "is today" I want the NSDatePicker to be
    > hidden, and then visible for the other two operators.
    >
    > I see other apps do this (Mail for example), but I can't seem to
    > accomplish the same thing.  I subclassed
    > NSPredicateEditorRowTemplate so I could alter the templateViews,
    > but I can't seem to determine which middle popup is selected.  What
    > is the best way to hide the NSDatePicker when the user selects the
    > menu item "is today" and then displays it for the other menu items?

    Hi Kimo,

    The right way to do this is to create two row templates.  From its
    templateViews method, the first one should return two views, like this:
    [Start Date / End Date] [is today]

    While the second one should return three  views, like this:
    [Start Date / End Date] [is the date / is before the date]
    _DATE_PICKER_

    (By [Start Date / End Date], I mean that view should be a popup
    button with two items titled respectively Start Date and End  Date).

    NSPredicateEditor will notice the identical titles in the initial
    popups of both templates, merge them together, and correctly show or
    hide the date picker based on what is selected in the second popup.

    Hope that helps,
    -Peter
previous month january 2008 next month
MTWTFSS
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
Go to today