Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

man2manno

macrumors member
Original poster
Mar 21, 2009
55
0
Hey guys I know this is a really simple question and I am just missing something little but why I am getting this Warning 'NSString' may not respond to '-test:' if my code looks like this...

Code:
-(NSString *)test:(NSString *)str {
	str = @"hello";
	return str;
}

[testStr test:otherStr];

As just an example. Thanks for the help.
 
Without more info I can't say exactly. First, you must have something like:

Code:
-(NSString *)test:(NSString *)str;

In the header (.h) file.

Second, wouldn't you call this like:

Code:
myOtherOtherString = [testStr test:otherStr];

Third, if you call this from within the object itself you would probably do something like:

Code:
myOtherOtherString = [self test:otherString];

Honestly, I work with enough different languages every day I can't remember if objective C would let you do:

Code:
[testStr test:otherStr];

Without it being defined like:

Code:
-(void)test:(NSString *)str;

My guess is no.


From rereading your post, you just seem confused. To do what you are doing you would have to setup a class named something different like "MySuperNSString" that subclasses NSString. Then you could init a MySuperNSString object that would have all the methods of the traditional NSString object but could also call a "test" method.

Your code defines a method that returns a NSString and takes an NSString for input, not adds a "test" method to the existing NSString. Like I said, I think you are confused:

Code:
-(NSString *)test:(NSString *)str; //NSString input, NSString output
 
Last edited:
Maybe you just need to add

Code:
-(NSString *)test:(NSString *)str;

to the header file?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.