On Fri, Aug 26, 2011 at 9:51 AM, glenn andreas <gandr...@mac.com> wrote:
> The App Store approval guidelines is pretty clear that the use of non-public 
> API is grounds for rejection.  NSToolbarView is undocumented, and therefore 
> doing anything that depends on that class or its (undocumented) behavior 
> would seem like grounds for rejection.  This would include adding a category 
> to replace a method (which is fraught with peril regardless - categories 
> aren't designed to replace existing methods, since you can't guarantee the 
> loading order of categories from OS release to OS release - including minor 
> updates), subclassing, method swizzling, or even testing to see if an object 
> is one of those undocumented classes.

A better idea would be to 1) file a Radar and then 2) call
method_exchangeImplementations sometime during launch to replace
NSClipView's implementation of -hitTest: with one that does the "Right
Thing". Perhaps something like this to minimize the effects of the
override:

// Warning, typed in Mail

@implementation NSToolbarView (MyFixes)

- (NSView *)replacement_hitTest:(NSPoint *)aPoint {
  NSView *foundView = [super hitTest:aPoint]; // call NSView's implementation
  if ([foundView tag] == MyCustomToolbarItemViewTag)
    return foundView;
  else
    return [self replacement_hitTest:aPoint]; // note that because of
how method_exchangeImplementations works, this will call the
_ORIGINAL_ IMP
}

+ (void)swapMethods {
  unsigned int methodCount = 0;
  Method *instanceMethods = class_copyMethodList(self, &methodCount);
  for (int i = 0; i < methodCount; i++) {
    Method *original = instanceMethods[i]
    if (method_getName(original) == @selector(hitTest:)) { // make
sure to only override -[NSToolbarView hitTest:]
      Method *replacement = class_getMethod(self,
@selector(replacement_hitTest:));
      method_exchangeImplementations(self, original, replacement);
      break;
    }
  }

  free(instanceMethods);
}

@end

Then call +[NSToolbarView(MyFixes) swapMethods] some time early in
your app's lifecycle, like -applicationWillFinishLaunching:.

> And even if it gets accepted, there is no guarantee that when you need to 
> make an emergency update to fix some critical bug that somehow slipped 
> through or later arose that you'd get accepted that time.

Make sure to file the Radar first so you can point at it if someone
flags your app.

--Kyle Sluder
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to