-
Notifications
You must be signed in to change notification settings - Fork 59
Description
I wrote a framework in Swift but cannot access classes marked as @objc public from cocoascript after loading the framework using Mocha.
I created an example to illustrate this. In my example, I wrote a Sketch plugin that uses Mocha to load my framework TestFramework.framework and attempts to access classes in the framework to display a window on command. The framework has a Swift class called WindowController which displays a Window when calling WindowController.shared().showWindow(nil) (or [[WindowController shared] showWindow:nil] in Objective-C). After loading the framework in Mocha, the class WindowController is never accessible despite being marked as @objc public. However, when I created an Objective-C class in the Framework called WrapperClass which is just a wrapper class for WindowController, I'm able to access it from CocoaScript.
I confirmed that both WindowController and WrapperClass are publicly accessible when the framework is loaded into an Objective-C app (TestAppOC which is also contained in my example).
To illustrate this, install my example plugin in Sketch and go to Plugins > Test Framework > Open with Swift or Open with Objective-C. The source code for the framework and test app can be opened in XCode in TestFramework/TestFramework.xcworkspace.
Am I doing something wrong or does CocoaScript not support calling Swift classes from dynamically loaded frameworks?