May Not Respond Warning.

Discussion in 'iOS Programming' started by man2manno, Dec 29, 2010.

  1. man2manno macrumors member

    Mar 21, 2009
    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...

    -(NSString *)test:(NSString *)str {
    	str = @"hello";
    	return str;
    [testStr test:otherStr];
    As just an example. Thanks for the help.
  2. ulbador, Dec 29, 2010
    Last edited: Dec 29, 2010

    ulbador macrumors 68000


    Feb 11, 2010
    Without more info I can't say exactly. First, you must have something like:

    -(NSString *)test:(NSString *)str;
    In the header (.h) file.

    Second, wouldn't you call this like:

    myOtherOtherString = [testStr test:otherStr];
    Third, if you call this from within the object itself you would probably do something like:

    myOtherOtherString = [self test:otherString];
    Honestly, I work with enough different languages every day I can't remember if objective C would let you do:

    [testStr test:otherStr];
    Without it being defined like:

    -(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:

    -(NSString *)test:(NSString *)str; //NSString input, NSString output
  3. bbarnhart macrumors 6502a


    Jan 16, 2002
    Maybe you just need to add

    -(NSString *)test:(NSString *)str;
    to the header file?

Share This Page