Professional Web Applications Themes

NSMenuItem warning ? - Mac Programming

NSMenuItem *menu_item; menu_item = [[NSApp mainMenu] itemWithTitle:"Special"]; The compiler complaint with this warning: assignment from incompatible pointer type What is wrong ?...

  1. #1

    Default NSMenuItem warning ?

    NSMenuItem *menu_item;

    menu_item = [[NSApp mainMenu] itemWithTitle:"Special"];

    The compiler complaint with this warning:

    assignment from incompatible pointer type

    What is wrong ?
    Alain Guest

  2. #2

    Default Re: NSMenuItem warning ?

    In article <168.1.3>, Alain Birtz
    <ca> wrote:
     

    itemWithTitle: returns an id <NSMenuItem>, not an NSMenuItem. This
    means that what is returned is an object which complies with the
    NSMenuItem protocol, not an object necessarily of the NSMenuItem class.
    Bottom line, I THINK (I'm sure someone will correct me if I'm wrong)
    you can safely do type cast the return value to be an NSMenuItem :

    menu_item = (NSMenuItem *)[[NSApp mainMenu] itemWithTitle:"Special"];

    but I think the more proper way would be:

    id <NSMenuItem> menu_item;

    Note that the protocol contains essentially all of the functionality
    that you would want; the distinction between the NSMenuItem protocol
    and the implementation of the NSMenuItem class so far as I can tell is
    private.

    Spence

    --
    James P. Spencer
    Rochester, MN

    "Badges?? We don't need no stinkin badges!"
    James Guest

  3. #3

    Default Re: NSMenuItem warning ?

    Yes. This was the problem.

    with "id <NSMenuItem> menu_item;" everything compile correctly.

    Thank you.


    In article <110420041025218496%net>,
    net wrote:
     
    >
    > itemWithTitle: returns an id <NSMenuItem>, not an NSMenuItem. This
    > means that what is returned is an object which complies with the
    > NSMenuItem protocol, not an object necessarily of the NSMenuItem class.
    > Bottom line, I THINK (I'm sure someone will correct me if I'm wrong)
    > you can safely do type cast the return value to be an NSMenuItem :
    >
    > menu_item = (NSMenuItem *)[[NSApp mainMenu] itemWithTitle:"Special"];
    >
    > but I think the more proper way would be:
    >
    > id <NSMenuItem> menu_item;
    >
    > Note that the protocol contains essentially all of the functionality
    > that you would want; the distinction between the NSMenuItem protocol
    > and the implementation of the NSMenuItem class so far as I can tell is
    > private.
    >
    > Spence[/ref]
    Alain Guest

Similar Threads

  1. What does this warning mean?
    By Tristan Cuschieri in forum PHP Development
    Replies: 1
    Last Post: August 23rd, 07:39 PM
  2. WARNING
    By Jeroen in forum Photography
    Replies: 25
    Last Post: July 28th, 06:41 PM
  3. WARNING ABOUT THE SMART WARNING!
    By PaulC in forum Windows XP/2000/ME
    Replies: 0
    Last Post: July 18th, 08:16 PM
  4. What to do about Warning???
    By Epiphany2B in forum Windows XP/2000/ME
    Replies: 5
    Last Post: July 18th, 07:46 PM
  5. warning - g o o g l e c r a c k . com
    By warning in forum Microsoft Access
    Replies: 1
    Last Post: July 11th, 04:19 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139