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 - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -