dot syntax issue? (Newb Question?)

  • Hello,

    I am new at Objective-C and Cocoa and have a quick question about the
    includes.  The following codes gives me the error noted in the comment:

          statusItem.menu = mainMenu;    // works fine
          statusItem.enabled = YES;        // error: request for member
    'enabled' in something not a structure or union
          statusItem.highlightMode = YES;    // works fine

    I notice that enabled is not defined in NSStatusItem.h and that is the
    reason for the error, when I change the code to:

          statusItem.menu = mainMenu;
          [statusItem setEnabled:YES];
          statusItem.highlightMode = YES;

    I don't get the error. This seems to be a hole in the dot syntax in
    objective-c 2.0.  To me it seems odd that I can use dot syntax on some
    properties and not others.

    Can someone explain to me why enabled does not exist in the
    NSStatusItem.h and why NSStatusItem.h does not use @property for its
    properties?

    Thanks,

    Gregor
  • On Nov 8, 2007, at 9:08 AM, Gregor Brandt wrote:

    > statusItem.menu = mainMenu;    // works fine
    > statusItem.enabled = YES;        // error: request for member
    > 'enabled' in something not a structure or union
    > statusItem.highlightMode = YES;    // works fine

    NSStatusItem defines:

    - (BOOL)isEnabled;

    (not -enabled).

    > Can someone explain to me why enabled does not exist in the
    > NSStatusItem.h
    >
    The implementors chose to store the information somewhere else.
    The implementation detail should not be a concern to you -- you should
    be using the public API (maintaining encapsulation).

    > and why NSStatusItem.h does not use @property for its properties?
    >
    It precedes the introduction of properties.  Most classes have not
    been retrofitted.

    In general, you are encouraged to use the dot syntax only with actual
    properties...

    mmalc
  • Just a random hypothetical: if one were to add a category on
    NSStatusItem and implement -enabled (and have it call through to -
    isEnabled), would that enable dot-syntax for the enabled property?

    On Nov 8, 2007, at 9:23 AM, mmalc crawford wrote:

    >
    > On Nov 8, 2007, at 9:08 AM, Gregor Brandt wrote:
    >
    >> statusItem.menu = mainMenu;    // works fine
    >> statusItem.enabled = YES;        // error: request for member
    >> 'enabled' in something not a structure or union
    >> statusItem.highlightMode = YES;    // works fine
    >
    > NSStatusItem defines:
    >
    > - (BOOL)isEnabled;
    >
    > (not -enabled).
    >
    >> Can someone explain to me why enabled does not exist in the
    >> NSStatusItem.h
    >>
    > The implementors chose to store the information somewhere else.
    > The implementation detail should not be a concern to you -- you
    > should be using the public API (maintaining encapsulation).
    >
    >
    >> and why NSStatusItem.h does not use @property for its properties?
    >>
    > It precedes the introduction of properties.  Most classes have not
    > been retrofitted.
    >
    > In general, you are encouraged to use the dot syntax only with
    > actual properties...
    >
    > mmalc
  • On Nov 8, 2007, at 9:28 AM, John Stiles wrote:

    > Just a random hypothetical: if one were to add a category on
    > NSStatusItem and implement -enabled (and have it call through to -
    > isEnabled), would that enable dot-syntax for the enabled property?
    >
    Why would you do that rather than using properties directly?

    @interface NSStatusItem (PropertySupport)
    @property (getter=isEnabled) BOOL enabled;
    @end

    mmalc
  • Ok, that makes sense.  I had assumed that all apple supplied libraries
    would allow the use of the dot-syntax and properties....silly me.

    Gregor

    On 8-Nov-07, at 10:23 AM, mmalc crawford wrote:

    >
    > On Nov 8, 2007, at 9:08 AM, Gregor Brandt wrote:
    >
    >> statusItem.menu = mainMenu;    // works fine
    >> statusItem.enabled = YES;        // error: request for member
    >> 'enabled' in something not a structure or union
    >> statusItem.highlightMode = YES;    // works fine
    >
    > NSStatusItem defines:
    >
    > - (BOOL)isEnabled;
    >
    > (not -enabled).
    >
    >> Can someone explain to me why enabled does not exist in the
    >> NSStatusItem.h
    >>
    > The implementors chose to store the information somewhere else.
    > The implementation detail should not be a concern to you -- you
    > should be using the public API (maintaining encapsulation).
    >
    >
    >> and why NSStatusItem.h does not use @property for its properties?
    >>
    > It precedes the introduction of properties.  Most classes have not
    > been retrofitted.
    >
    > In general, you are encouraged to use the dot syntax only with
    > actual properties...
    >
    > mmalc
    >
  • It would, but in general it's really not a good idea to be adding
    categories or properties on kit classes (just for this kind of
    purpose) since it may conflict with @property declarations Apple may
    introduce in the future.

    If the dot syntax doesn't work for some reason or another, the best
    approach may be to stick to the bracket syntax for now.

    Ali

    On Nov 8, 2007, at 09:28 , John Stiles wrote:

    > Just a random hypothetical: if one were to add a category on
    > NSStatusItem and implement -enabled (and have it call through to -
    > isEnabled), would that enable dot-syntax for the enabled property?
    >
    >
    > On Nov 8, 2007, at 9:23 AM, mmalc crawford wrote:
    >
    >>
    >> On Nov 8, 2007, at 9:08 AM, Gregor Brandt wrote:
    >>
    >>> statusItem.menu = mainMenu;    // works fine
    >>> statusItem.enabled = YES;        // error: request for member
    >>> 'enabled' in something not a structure or union
    >>> statusItem.highlightMode = YES;    // works fine
    >>
    >> NSStatusItem defines:
    >>
    >> - (BOOL)isEnabled;
    >>
    >> (not -enabled).
    >>
    >>> Can someone explain to me why enabled does not exist in the
    >>> NSStatusItem.h
    >>>
    >> The implementors chose to store the information somewhere else.
    >> The implementation detail should not be a concern to you -- you
    >> should be using the public API (maintaining encapsulation).
    >>
    >>
    >>> and why NSStatusItem.h does not use @property for its properties?
    >>>
    >> It precedes the introduction of properties.  Most classes have not
    >> been retrofitted.
    >>
    >> In general, you are encouraged to use the dot syntax only with
    >> actual properties...
    >>
    >> mmalc

  • On Nov 8, 2007, at 9:33 AM, mmalc crawford wrote:

    >
    > On Nov 8, 2007, at 9:28 AM, John Stiles wrote:
    >
    >> Just a random hypothetical: if one were to add a category on
    >> NSStatusItem and implement -enabled (and have it call through to -
    >> isEnabled), would that enable dot-syntax for the enabled property?
    >>
    > Why would you do that rather than using properties directly?
    >
    > @interface NSStatusItem (PropertySupport)
    > @property (getter=isEnabled) BOOL enabled;
    > @end

    Err, why not? Whatever gets the job done :)

    Anyway, this looks like a good solution. Why didn't you suggest this
    in the beginning?
  • On Nov 8, 2007, at 9:40 AM, John Stiles wrote:
    > On Nov 8, 2007, at 9:33 AM, mmalc crawford wrote:
    >> On Nov 8, 2007, at 9:28 AM, John Stiles wrote:
    >>> Just a random hypothetical: if one were to add a category on
    >>> NSStatusItem and implement -enabled (and have it call through to -
    >>> isEnabled), would that enable dot-syntax for the enabled property?
    >>>
    >> Why would you do that rather than using properties directly?
    >>
    >> @interface NSStatusItem (PropertySupport)
    >> @property (getter=isEnabled) BOOL enabled;
    >> @end
    >
    > Err, why not? Whatever gets the job done :)
    >
    Because you're needlessly adding another method call and hiding
    information.

    > Anyway, this looks like a good solution. Why didn't you suggest this
    > in the beginning?
    >
    See Ali's reply.

    mmalc
  • On Nov 8, 2007, at 9:36 AM, Gregor Brandt wrote:

    > Ok, that makes sense.  I had assumed that all apple supplied
    > libraries would allow the use of the dot-syntax and
    > properties....silly me.
    >
    They do, when they follow the appropriate naming convention...

    mmalc
  • On Nov 8, 2007, at 9:44 AM, mmalc crawford wrote:

    >
    > On Nov 8, 2007, at 9:40 AM, John Stiles wrote:
    >> On Nov 8, 2007, at 9:33 AM, mmalc crawford wrote:
    >>> On Nov 8, 2007, at 9:28 AM, John Stiles wrote:
    >>>> Just a random hypothetical: if one were to add a category on
    >>>> NSStatusItem and implement -enabled (and have it call through to
    >>>> -isEnabled), would that enable dot-syntax for the enabled property?
    >>>>
    >>> Why would you do that rather than using properties directly?
    >>>
    >>> @interface NSStatusItem (PropertySupport)
    >>> @property (getter=isEnabled) BOOL enabled;
    >>> @end
    >>
    >> Err, why not? Whatever gets the job done :)
    >>
    > Because you're needlessly adding another method call and hiding
    > information.
    >
    >> Anyway, this looks like a good solution. Why didn't you suggest
    >> this in the beginning?
    >>
    > See Ali's reply.

    So theoretically, in 10.6 Apply may do something like what you
    suggested:

    >>> @interface NSStatusItem (PropertySupport)
    >>> @property (getter=isEnabled) BOOL enabled;
    >>> @end

    and at that point, if we had done it separately in our own code, it
    would lead to an error condition?
  • If the definitions were in perfect sync, it may be fine; I am not
    sure.  There is a chance that Apple's definition may be different, and
    that will likely cause a conflict, at least at compile time.  And in
    fact, since an @property declaration represents metadata, a difference
    may lead to a binary incompatibility.
    Ali

    On Nov 8, 2007, at 09:49 , John Stiles wrote:

    >
    > On Nov 8, 2007, at 9:44 AM, mmalc crawford wrote:
    >
    >>
    >> On Nov 8, 2007, at 9:40 AM, John Stiles wrote:
    >>> On Nov 8, 2007, at 9:33 AM, mmalc crawford wrote:
    >>>> On Nov 8, 2007, at 9:28 AM, John Stiles wrote:
    >>>>> Just a random hypothetical: if one were to add a category on
    >>>>> NSStatusItem and implement -enabled (and have it call through to
    >>>>> -isEnabled), would that enable dot-syntax for the enabled
    >>>>> property?
    >>>>>
    >>>> Why would you do that rather than using properties directly?
    >>>>
    >>>> @interface NSStatusItem (PropertySupport)
    >>>> @property (getter=isEnabled) BOOL enabled;
    >>>> @end
    >>>
    >>> Err, why not? Whatever gets the job done :)
    >>>
    >> Because you're needlessly adding another method call and hiding
    >> information.
    >>
    >>> Anyway, this looks like a good solution. Why didn't you suggest
    >>> this in the beginning?
    >>>
    >> See Ali's reply.
    >
    >
    > So theoretically, in 10.6 Apply may do something like what you
    > suggested:
    >
    >>>> @interface NSStatusItem (PropertySupport)
    >>>> @property (getter=isEnabled) BOOL enabled;
    >>>> @end
    >
    > and at that point, if we had done it separately in our own code, it
    > would lead to an error condition?
    >
previous month november 2007 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    
Go to today