Reputation: 6862
I have been struggling with this for some time now.
There have been many times I wanted to change something minor in a control, but I had to redraw the entire thing just to adjust it. Like a NSPathControl, I just wanted to change the background of the Path Control, I ended up creating a whole new control just for that small adjustment...
Apple uses private methods, like the following:
- (void)_drawContextMenuHighlightForIndexes:(NSIndexSet *)rowIndexes clipRect:(NSRect)rect;
I have found this in a Stackoverflow-Post.
How should I know about these? I don't think they are meant to be public, but this is just WAY easier. Where do these people know this from? Are there any references? I wouldn't need to know any source code, I would only have to know the names of the private methods.
So my question, how can I get the names of private methods of AppKit classes?
Thanks
Upvotes: 1
Views: 786
Reputation: 50119
you query the runtime for methods/properties/variables a class has or you use a handy tool (DDDump) from github that does this at runtime by adding a category on NSObject
NSLog(@"%@", [obj dump]);
not requested but also really useful in that context is the NSObjCMessageLoggingEnabled environment variable, which -when YES- allows you to see any dispatching done!
oh and getting all notifications is always a good idea too :)
Upvotes: 1
Reputation: 40211
Private class method names can be obtained using Obj-C runtime functions. To get a list of methods of a class you can do something like:
unsigned int methodCount;
Method *methods = class_copyMethodList(theClass, &methodCount);
for (int i = 0; i < methodCount; i++) {
Method method = methods[i];
NSString *methodName = NSStringFromSelector(method_getName(method));
// collect name in an array or print it.
}
free(methods);
There is also a handy terminal tool that does this for you called class-dump.
Upvotes: 3