swift - Sharing code from an app as a framework for making plug-ins -


i experimenting loading classes bundles @ runtime. let me explain i'm trying do. question @ end please bear me.

suppose making game (as cocoa .app) , game contains classes can subclassed mods , registered game (as cocoa .bundle). whole infrastructure consist out of 3 main pairts:

game.app

the game @ least have 3 classes:

  1. a class represents object in game can subclassed;
  2. a class of subclass can used principal class of bundle;
  3. a static class called app delegate load bundles.

this code last two:

class principal {     func register() {         //for plugins register classes     } }  class loader {     static func load() {         let enumerator = filemanager.default.enumerator(at: bundle.main.builtinpluginsurl!, includingpropertiesforkeys: nil)          while let element = enumerator?.nextobject() as? url {             if element.pathextension == "bundle" {                 let bundle = bundle(url: element)                  if let mod = bundle?.principalclass as? principal.type {                     let instance:principal = mod.init()                     instance.register()                 }             }         }     } } 

kit.framework

to used plugin bundles make subclasses of classes game.

plugin.bundle

links kit.framework , subclasses classes. registers classes in principal class so:

class plugin:principal {     override func register() {         //registers types (singleton) registry         registry.registertype(something.type)     } } 

i got of work putting code (except loader) in framework , having both app , bundle link framework. ideally keep code in game can't cast registered types corresponding types in game classes compiled separately in app , in framework , different entities.

now question if there way either link dynamically .app framework or way share code developing plugins without using framework , while keeping code in .app.


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -