Problem with XCode 4 .6

Discussion in 'Mac Programming' started by Senor Cuete, Feb 4, 2013.

  1. Senor Cuete, Feb 4, 2013
    Last edited: Feb 4, 2013

    Senor Cuete macrumors 6502

    Nov 9, 2011
    I upgraded from XCode 4.5 to XCode 4.6 two days ago. Now none of my class methods will work if they have more that one parameter. For example:

    @interface  myClass : NSWindowController <NSTextFieldDelegate>
    - (void) myMethodName: (int) x menu: (NSPopUpButton *) myMenu;
    - (void) myMethodName: (int) x menu: (NSPopUpButton *) myMenu
    When I send my object a message such as:
    [self myMethodName: (int) x menu: (NSPopUpButton *) myMenu];
    It will cause an error: unrecognized selector sent to instance 0xnnnnnnnnn.

    This builds correctly with no warnings and it worked in earlier versions of Xcode.

    What's wrong?

    I turned the Apple LLVM compiler 4.2 - warnings -Objective C

    Multiple Definition Types for Selector
    Strict Selector Matching and
    Undeclared Selector

    to yes and rebuilt the project. No warning during build but crash during execution.
  2. gnasher729 macrumors P6


    Nov 25, 2005
    There's a bug in your code.

    First, remove the casts when you send the message. Casts will only serve to hide problems. Then turn on all the warnings in Xcode that you can turn on and fix any problems that Xcode tells you about.

    I'd say "self" is not what you think it is. Which could easily happen because you cast an object of type X to type Y.

    What about some simple debugging? Breakpoint on the line that crashes, and look at the contents of variables, including self.
  3. Senor Cuete thread starter macrumors 6502

    Nov 9, 2011
    I don't have the casts in my code, I carelessly put them in my example.

    I don't cast any object to the type of self or any of the variables such as the int or (NSPopUpButton *). The calls to [self selector] are in the implementation of the object. Breakpoints are set at offending call to [self selector]. self is a valid allocated object instance with a hex address. XCode finds no problems when building but crashes during execution. This worked with Older versions. XCode seems to be building the project with no problem but failing to recognize the selector at runtime. I'll look at the build settings. Maybe I have some setting like build for 10.8 set and I'm using 10.7. I'll check.

    It probably doesn't matter but this project was written with Objective C 1 - no reference counting or ARC.
  4. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    Copy and paste the complete text of the actual error message. You've left out an important part of it, the part that identifies what the actual class of the object is.

    Also post the exact actual code, rather than the hypotheticals myMethodName and myClass. We need to see exactly what the code is. Hypotheticals haven't been compiled.

    If you can't post those right away, do it later when you have the actual code and error messages at hand. Accuracy is important.
  5. Senor Cuete thread starter macrumors 6502

    Nov 9, 2011
    2013-02-04 14:52:04.431 myApp[5041:303] -[myClassName myMethodName:myInt:]: unrecognized selector sent to instance 0x102407b10
    2013-02-04 14:52:04.432 myApp[5041:303] Exception detected while handling key input.

    Then a whole list of errors.

    All possible error messages turned on in project and target settings but build generates no errors.
  6. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    Please post your actual code, at the point where the error is coming from. That is, at the point where myMethodName:myInt: is actually being messaged.

    Your first post had this:
    [self myMethodName: (int) x menu: (NSPopUpButton *) myMenu];
    The method signature is myMethodName:menu: . This differs from what's in your error message above, which is myMethodName:myInt: .

    Also, your class name in your first post is myClass, yet the class name in the error message is myClassName.

    If those are the actual method and class names, then the problem should be clear: you don't have the method you seem to think you do. Why this might be so can only be guessed at without seeing your actual code. It may be an optional method in a protocol. Your code may be doing something unexpected. We don't know, because you have not yet posted your actual code, only a hypothetical. The hypothetical is clearly not the same as what's in the error message, because the methods are clearly different.

    If those are not the actual method and class names, then please post the actual unaltered class name, method name, and the actual unaltered error message output.

    When you say the build generates no errors, do you mean no errors or warnings? Because you may only be getting a warning.
  7. Senor Cuete thread starter macrumors 6502

    Nov 9, 2011
    No errors or warnings, even with all warnings turned on
  8. Senor Cuete thread starter macrumors 6502

    Nov 9, 2011

    First I changed the names of the parameters so there was no name collision with variables in some .h files for some .c files in the project. I don't think that this was the problem.

    Then I carefully copied the parameters, etc. to the method implementations so that the parameters, etc. are exactly the same. This solved the problem. I think that there was a typo in the name of one or more parameter or parameter name. It's surprising that XCode wouldn't catch this and at least give me a warning when I built the project.

Share This Page