May Not Respond Warning.

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

  1. man2manno macrumors member

    Joined:
    Mar 21, 2009
    #1
    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.
     
  2. ulbador, Dec 29, 2010
    Last edited: Dec 29, 2010

    ulbador macrumors 68000

    ulbador

    Joined:
    Feb 11, 2010
    #2
    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
    
     
  3. bbarnhart macrumors 6502a

    bbarnhart

    Joined:
    Jan 16, 2002
    Location:
    Stilwell, Kansas
    #3
    Maybe you just need to add

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

Share This Page