0

When the following code is executed

style = [self performSelector:sel withObject:(id)state]; 

The breakpoint in sel does not hit. Is this normal behavior?

NSString* key = state == UIControlStateNormal
    ? selector
    : [NSString stringWithFormat:@"%@%d", selector, state];
  TTStyle* style = [_styles objectForKey:key];
  if (!style) {
    SEL sel = NSSelectorFromString(selector);
    if ([self respondsToSelector:sel]) {
      style = [self performSelector:sel withObject:(id)state];
      if (style) {
        if (!_styles) {
          _styles = [[NSMutableDictionary alloc] init];
        }
        [_styles setObject:style forKey:key];
      }
    }
  }
ThinkingStiff
  • 64,767
  • 30
  • 146
  • 239
user210504
  • 1,749
  • 2
  • 17
  • 36
  • No, it's not normal. Try `[self respondsToSelector:sel]` and see if it returns `YES` – Art Gillespie Jan 13 '11 at 05:27
  • So, the function does respond to this selector. This is a snapshot from three20style code. What i see is that the function does get called, but the values returned are incorrect. When I place the breakpoint it is not hit – user210504 Jan 13 '11 at 05:50

2 Answers2

1

In one of your comments on your post, you mention that this code is from the three20style library, and that when you place the breakpoint, it is not hit. Probably what's happening is that you are following Three20's recommended practice for linking the Three20 libraries: In the "Other Linker Flags" section of the Build settings, you probably have a whole bunch of -force-load arguments, something sort of like this:

-force-load libThree20UICommon.a -force-load libThree20.a ...

The problem is, it turns out that when you link that way, breakpoints don't work. As a workaround, only in your Debug configuration (not in your Release configuration), remove all those arguments from the "Other Linker Flags", and put these in instead:

-all_load -ObjC

I'm not intimately familiar with the exact difference between these flags; all I know is, using -all_load -ObjC allows your breakpoints to work. I wouldn't recommend changing the setting for the Release configuration, since I'm not sure of the exact impact of the change.

Mike Morearty
  • 9,953
  • 5
  • 31
  • 35
  • I prefer the dummy class solution, as proposed here: http://blog.binaryfinery.com/universal-static-library-problem-in-iphone-sd Make sure you put the macro in the .m file, not the header, to avoid duplicate symbol errors. – CodeSmile Feb 26 '11 at 14:02
0

Try style = [self performSelector:@selector(sel) withObject:(id)state];

Suresh Varma
  • 9,750
  • 1
  • 60
  • 91