Strange warnings

Discussion in 'Mac Programming' started by netytan, Mar 4, 2006.

  1. macrumors 6502

    netytan

    Joined:
    May 23, 2004
    #1
    Hey all,

    Things are going pretty well on my little project, but I have noticed a several little warnings that it doesn't seem I can fix unless I for instance overriding alloc to do nothing.

    .../CSMainDocument.m:39: warning: `CSMainWindowController' may not respond to `+alloc'
    .../CSMainDocument.m:39: warning: (Messages without a matching method signature
    .../CSMainDocument.m:39: warning: will be assumed to return `id' and accept
    .../CSMainDocument.m:39: warning: `...' as arguments.)
    .../CSMainDocument.m:42: warning: passing argument 1 of 'addWindowController:' from incompatible pointer type

    All of these are related to alloc not explicitly being defined in my subclass of NSWindowController, now I don't see the point in implementing alloc and doing nothing with it.

    Is it ok to just ignore the warnings, or is there a better way that I can fix them?

    I'm loathed to leave them there but I also don't want add code bloat for no reason. It seems that Xcode is a little picky about this kind of thing, it also doesn't handle code completion for subclasses very well :rolleyes:.

    Thanks for any advice,

    Mark.
     
  2. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    What type is CSMainWindowController? Have you imported it's header or just declared it's existence via a @class directive? If you have imported it's header are you sure you've declared it's superclass? If you haven't imported it's header and are using @class is there a reason you can't import the header?
     
  3. Guest

    caveman_uk

    Joined:
    Feb 17, 2003
    Location:
    Hitchin, Herts, UK
    #3
    IIRC alloc is defined in NSObject which all other classes are decended from. You shouldn't need to define alloc as it's inherited. Sounds like something's wrong somewhere with the way you're doing things...

    Generally warnings are there for a reason.
     
  4. macrumors 601

    zimv20

    Joined:
    Jul 18, 2002
    Location:
    chicago
    #4
    time to post some code...
     
  5. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #5
    This is all true but I've noticed in recent XCode versions that if you define a variable as say

    id myClassInstance

    and then try and call a method that is in NSObject on it then you get warnings. I think this is because id is defined as void * and the compiler cannot be sure that it's even an NSObject. A way round this is to define it as

    id<NSObject> myClassInstance
     
  6. Guest

    caveman_uk

    Joined:
    Feb 17, 2003
    Location:
    Hitchin, Herts, UK
    #6
    Ah, I rarely define anything as id so I might not have seen it. Obviously sometimes you need to define things as id - I just tend to avoid it.
     
  7. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #7
    I generally only use id for delegates. It's getting a bit annoying as I used to just do:

    id<MyDelegateProtocol> delegate;

    but now I'm needing

    id<NSObject,MyDelegateProtocol> delegate;

    It's not all that much extra work really but I'm sure the first one used to work with no warnings!
     
  8. thread starter macrumors 6502

    netytan

    Joined:
    May 23, 2004
    #8
    Likewise, when I first used Cocoa about a year ago I never get any errors like this then I went away to work with other things and no warnings :). In any case I was using @class because I read that it reduced compile times. I included the header and the warnings went away so I'm happy now ;).

    Thanks a lot guys,

    Mark.
     

Share This Page