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

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -