PDA

View Full Version : runtime error with an NSString function




tomerw
Apr 10, 2009, 07:30 PM
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 ?



eddietr
Apr 10, 2009, 07:44 PM
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.

CocoaPuffs
Apr 10, 2009, 08:02 PM
And lastly if you wrap code in code tags, it's much easier to read.

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

mccannmarc
Apr 11, 2009, 04:22 AM
have you tried:-


+(NSString*) getImagePath:(int)selectedImage
{
return([NSString stringWithString:@"something"]);
}

tomerw
Apr 11, 2009, 07:44 AM
I tried stringWithString, same problem.
some more detailed information :

OpenerUtil.h

@interface OpenerUtil {}
+(NSString*) getImagePath:(NSInteger)selectedImage;

@end


OpenerUtil.m

#import "OpenerUtil.h"
@implementation OpenerUtil

+(NSString*) getImagePath:(NSInteger)selectedImage{
return @"something";
}
@end


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?

Thanks.

eddietr
Apr 11, 2009, 10:20 AM
If I move the getImagePath method to my MainView.m, it works.


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

tomerw
Apr 11, 2009, 11:11 AM
I don't explicitly use NSInvocation anywhere.
I do have two timers, but even if I disable both, the problem remains.

eddietr
Apr 11, 2009, 11:19 AM
I don't explicitly use NSInvocation anywhere.
I do have two timers, but even if I disable both, the problem remains.

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.

tomerw
Apr 11, 2009, 11:26 AM
OpenerUtil did not inherit from NSObject.

eddietr
Apr 11, 2009, 11:30 AM
OpenerUtil did not inherit from NSObject.

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.