开发者

Singletons in Cocoa Plugins

开发者 https://www.devze.com 2022-12-31 06:48 出处:网络
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 (e

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).开发者_开发知识库


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消