I am currently writing a framework for creating plugins for my OS X application. These plugins are loaded as NSBundle
s, and the bundles' principalClass
es are used to run the plugin code. However, I can't figure out how to declare that the principalClass
object conforms to my protocol.
let bundles = CFBundleCreateBundlesFromDirectory(kCFAllocatorDefault, NSURL(fileURLWithPath: bundleDirectory), "bundle") as NSArray
for bundle in bundles
{
let bundleClass = bundle.principalClass!!
if (bundleClass.conformsToProtocol(MyProtocol.self))
{
//Produces compiler error:
//"Cannot downcast from 'AnyClass' to non-@objc protocol type 'MyProtocol'"
let loadedClass = bundleClass as MyProtocol
}
}
What is the proper syntax for declaring that it conforms to this protocol?
(Also, this protocol is declared @objc
so I'm not sure why it says "non-@objc" protocol.)