1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

runtime error with an NSString function

Discussion in 'iPhone/iPad Programming' started by tomerw, Apr 10, 2009.

  1. macrumors newbie

    Newbie to xcode.
    I wrote the following function :

    +(NSString*) getImagePath:(int)selectedImage{
    return @"something";

    and I get a runtime error everytime I call it. Maybe i'm misunderstanding something about NSString ?
  2. macrumors 6502a

    So one really useful tip is to copy/paste the actual error. Those details may not be meaningful to you yet, but it's good info for someone else trying to help.

    Also, can you post the code that calls this method?

    And lastly if you wrap code in code tags, it's much easier to read.
  3. macrumors 68010

    Ya, cause I thought the error was due to the sad face being part of the code.
  4. macrumors 6502


    have you tried:-

    +(NSString*) getImagePath:(int)selectedImage
    return([NSString stringWithString:@"something"]);
  5. macrumors newbie

    detailed (formatted) information about the problem

    I tried stringWithString, same problem.
    some more detailed information :

    @interface OpenerUtil {}
    +(NSString*) getImagePath:(NSInteger)selectedImage;
    #import "OpenerUtil.h"
    @implementation OpenerUtil
    +(NSString*) getImagePath:(NSInteger)selectedImage{
    	return @"something";
    in MainView.h, I have :
    #import OpenerUtil.h
    And the call to the method looks like this :
    NSString *test = [OpenerUtil getImagePath:0];
    My Error looks like this :
    2009-04-11 15:44:05.391 BeerOpener[581:20b] *** NSInvocation: warning: object 0x74e0 of class 'OpenerUtil' does not implement methodSignatureForSelector: -- trouble ahead
    2009-04-11 15:44:05.399 BeerOpener[581:20b] *** NSInvocation: warning: object 0x74e0 of class 'OpenerUtil' does not implement doesNotRecognizeSelector: -- abort
    If I move the getImagePath method to my MainView.m, it works.
    What am I doing wrong here?

  6. macrumors 6502a

    OK, you're using an NSInvocation. Is this being called from a timer or something?
  7. macrumors newbie

    I don't explicitly use NSInvocation anywhere.
    I do have two timers, but even if I disable both, the problem remains.
  8. macrumors 6502a

    Well, if it's a direct method call like you posted, then you shouldn't be seeing an NSInvocation.

    Something else is going on here. I'd have to see more code than what you're posting to be able to figure it out.

    But to answer your general question, you can return a literal string @"Some String" directly as an NSString*. That part is not your problem. So I would look elsewhere.

    Hope that helps.
  9. macrumors newbie

    problem fixed.

    OpenerUtil did not inherit from NSObject.
  10. macrumors 6502a

    Oh, didn't even notice that. Just FYI, if it's a direct method call like [SomeClass someMethod:0], then that wouldn't matter.

    But if you're using an NSInvocation (via a timer for example) then yes, your class needs be a subclass of NSObject.

    Glad you figured it out.

Share This Page