Pergunta

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).

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top