I am currently writing multiple plugins entirely in objective-C, and I want them to communicate with each other.
The problem is, I couldn’t find a way to import each other’s headers in the source file.
I found out that if you write a plugin in Python, the contents of every other installed plugins are accessible (i.e. their paths are appended to sys.path, so you can import them).
Is there a similar way to dynamically link another installed plugin using objective-C??
You can access everything from other plugins. The connection is not done by importing the headers. That is just telling the compiler what the other object can do. In your case, add the headers to both plugins. Or define a protocol that each plugin implements:
You need to check the result of NSClassFromString and show an error message that the other plugin is missing.
Or, depending what you are trying to do, put everything into one plugin. There are callbacks for most things that you can add broader functionality. e.g. reporter can handle mouse commands and file-format plugins can draw.
What a great idea to access plugins from each other. I never really thought about that, even though I often had an unconscious guts feeling that it would be incredibly handy from time to time. I think I’ll give it a try, as well. Thanks for the inspirational thread!
If you “link” to some code (as you do to the GlyphsCore framework), then you can use the classes directly ([[GlyphsFilterRemoveOverlap alloc] init];). because the linking tells the code where to find that class. If you don’t link to it, you still can get to the class but that is an active lookup in the runtime. So in performance critical code it might be a good idea to cache the class.
When you call a method, the runtime doesn’t know much about the object you are calling the method on. It doesn’t know about the header and all the definitions there. Those are only help the compiler give you some feedback.
So in cases like this, you need to be really careful when you load a class from a different plugins. You should never change the API because you never know if the user has the most recent version of both plugins. Or if you have to change the API your code needs to check if the loaded plugins are the right version.
Did anything change with NSClassFromString(@"GlyphsFilterRemoveOverlap");? I always get nil now in Glyphs 3. Not sure since which build, but I think it worked before.
Same when doing it with python like print(NSClassFromString("GlyphsFilterRemoveOverlap")) -→ None
Many of my Plugins use it. Eg. Presenter, Show Stems (both even as a user option), variable Font Preview, … Basically I need the layer a as removed overlap version, as I had before.