tags:

views:

11

answers:

1

How would I get a hold of a singleton in the main application from a SIMBL plugin? When I try to call something like [ProcessControl sharedInstance], I get an error that ProcessControl is undefined (even though it is declared in a header file).

+1  A: 

Use NSClassFromString to look up the class at run time, then send it the sharedInstance message as normal.

Be prepared for NSClassFromString to return Nil or for the message to the class to fail. Either one will happen if the application developer removes or renames the class or its singleton method. You assume this risk whenever you write a plug-in for an application that doesn't have a documented, supported plug-in API.

Your “plug-in” will be most robust if all of your code that interacts with the application's classes and instances thereof looks thoroughly paranoid.

Peter Hosey
I knew there had to be a function like this but for the life of me I couldn't find it.A nice thing about SIMBL is that you can limit a plugin to run on only the versions you have tested it with.
David Beck