2

How do I solve this warning?

enter image description here

The warning is "undeclared selector 'forwardGeocoderDidFail:withErrorMessage:'". Why am I getting this warning, and how can I solve it?

This is my code:

if (!handeledByBlocks && self.delegate) {
    if (!parseError && parser.statusCode == G_GEO_SUCCESS)
    {
        [self.delegate forwardGeocodingDidSucceed:self withResults:parser.results];
    }
    else if ([self.delegate respondsToSelector:@selector(forwardGeocoderDidFail:withErrorMessage:)])
    {
        [self.delegate forwardGeocodingDidFail:self withErrorCode:parser.statusCode andErrorMessage:[parseError localizedDescription]];
    }        
}
hichris123
  • 10,145
  • 15
  • 56
  • 70
M.B Kakadiya
  • 576
  • 1
  • 5
  • 18
  • `forwardGeocoderDidFail` method is missing. – modusCell Jul 31 '14 at 17:51
  • Show your protocol definition. Also note that what you check for with `respondsToSelector` is not the same as the method you actually call. That's not good. – rmaddy Jul 31 '14 at 17:52
  • Check out this answer http://stackoverflow.com/questions/18570907/should-i-fix-xcode-5-semantic-issue-undeclared-selector – pkatsourakis Jul 31 '14 at 17:54
  • Post the forwardGeocoderDidFail:withErrorMessage: definition. There must be something wrong with it or the respondsToSelector parameter. Maybe the name is spelled wrong or it has not been defined at all. – Dko Jul 31 '14 at 17:54
  • @PanoKatsourakis That is not a good solution. Actually fixing the problem is a much better solution. – rmaddy Jul 31 '14 at 17:55
  • I was just trying to help out @rmaddy. Responses like yours make me not want to participate on this site. – pkatsourakis Jul 31 '14 at 18:05
  • @PanoKatsourakis I was simply trying to point out that it's better to fix the problem than to hide it. That's all. – rmaddy Jul 31 '14 at 18:13

2 Answers2

6

Replace

[self.delegate respondsToSelector:@selector(forwardGeocoderDidFail:withErrorMessage:)]

with

[self.delegate respondsToSelector:@selector(forwardGeocodingDidFail:withErrorCode:andErrorMessage:)]
Sviatoslav Yakymiv
  • 7,887
  • 2
  • 23
  • 43
1

Whatever you're setting as the delegate does not have a public method called: forwardGeocoderDidFail:withErrorMessage:

That's what's causing the warning that you want to fix.

In the line below, you're calling a method with a different signature.

forwardGeocoderDidFail: withErrorCode: andErrorMessage:

Make sure whatever object is your delegate actually implements the correct method, and that respondsToSelector actually checks the one you want.

mc01
  • 3,750
  • 19
  • 24
  • 1
    Given that it seems the OP has no problem calling the `forwardGeocodingDidFail:withErrorCode:andErrorMessage:` method on the next line, I think it's simply a typo in the `respondsToSelector` call. – rmaddy Jul 31 '14 at 17:54
  • Yes, but "just a typo" doesn't explain the actual error message or why it's occurring. The mismatch in method signatures is "a typo" but why that matters & what result it has is also important. – mc01 May 11 '17 at 16:22