Swift declare that AnyClass object implements protocol -


i writing framework creating plugins os x application. these plugins loaded nsbundles, , bundles' principalclasses used run plugin code. however, can't figure out how declare principalclass object conforms protocol.

let bundles = cfbundlecreatebundlesfromdirectory(kcfallocatordefault, nsurl(fileurlwithpath: bundledirectory), "bundle") nsarray  bundle in bundles {     let bundleclass = bundle.principalclass!!      if (bundleclass.conformstoprotocol(myprotocol.self))     {         //produces compiler error:         //"cannot downcast 'anyclass' non-@objc protocol type 'myprotocol'"         let loadedclass = bundleclass myprotocol     } } 

what proper syntax declaring conforms protocol? (also, protocol declared @objc i'm not sure why says "non-@objc" protocol.)

try: bundleclass myprotocol.protocol. docs here.

btw, code can simplified

let bundles = cfbundlecreatebundlesfromdirectory(kcfallocatordefault, nsurl(fileurlwithpath: bundledirectory), "bundle") nsarray bundle in bundles {     if let loadedclass = bundle.principalclass as? myprotocol.protocol {         // ...     } } 

Comments

Popular posts from this blog

javascript - ScrollTo Effect (href to div) -

javascript - ng-class not responding to change in model in Angular? -

javascript - document.registerElement extending HTMLInputElement prototype while using custom tag name to avoid implicit browser style -