runtime error with an NSString function

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

  1. macrumors newbie

    Joined:
    Apr 10, 2009
    #1
    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

    Joined:
    Oct 29, 2006
    Location:
    Virginia
    #2
    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

    Joined:
    Aug 23, 2008
    #3
    Ya, cause I thought the error was due to the sad face being part of the code.
     
  4. macrumors 6502

    mccannmarc

    Joined:
    Aug 15, 2008
    Location:
    Manchester, UK
    #4
    have you tried:-

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

    Joined:
    Apr 10, 2009
    #5
    detailed (formatted) information about the problem

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

    OpenerUtil.h
    Code:
    @interface OpenerUtil {}
    +(NSString*) getImagePath:(NSInteger)selectedImage;
    
    @end
    
    OpenerUtil.m
    Code:
    #import "OpenerUtil.h"
    @implementation OpenerUtil
    
    +(NSString*) getImagePath:(NSInteger)selectedImage{
    	return @"something";
    }
    @end
    
    in MainView.h, I have :
    Code:
    #import OpenerUtil.h
    
    And the call to the method looks like this :
    Code:
    NSString *test = [OpenerUtil getImagePath:0];
    
    My Error looks like this :
    Code:
    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?

    Thanks.
     
  6. macrumors 6502a

    Joined:
    Oct 29, 2006
    Location:
    Virginia
    #6
    OK, you're using an NSInvocation. Is this being called from a timer or something?
     
  7. thread starter macrumors newbie

    Joined:
    Apr 10, 2009
    #7
    I don't explicitly use NSInvocation anywhere.
    I do have two timers, but even if I disable both, the problem remains.
     
  8. macrumors 6502a

    Joined:
    Oct 29, 2006
    Location:
    Virginia
    #8
    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. thread starter macrumors newbie

    Joined:
    Apr 10, 2009
    #9
    problem fixed.

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

    Joined:
    Oct 29, 2006
    Location:
    Virginia
    #10
    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