Skip to content

Instantly share code, notes, and snippets.

@53ningen
Last active February 9, 2016 10:26
Show Gist options
  • Save 53ningen/6a5b42bcfda31b2d2af5 to your computer and use it in GitHub Desktop.
Save 53ningen/6a5b42bcfda31b2d2af5 to your computer and use it in GitHub Desktop.
typealias ContextType = protocol<AComponent, ABComponent>
class Context {
private let type: ContextType.Type
init(type: ContextType.Type) { self.type = type }
var a: A { return type.a }
var ab: AB { return type.ab }
}
class DebugContext: DefaultAComponent, DefaultABComponent {
static let a: A = DebugContext.createA()
static let ab: AB = DebugContext.createAB()
}
class ReleaseContext: DefaultAComponent, SimpleABComponent {
static let a: A = ReleaseContext.createA()
static let ab: AB = ReleaseContext.createAB()
}
let debugContext = Context(type: DebugContext.self)
debugContext.ab.getAB() // => ab
let releaseContext = Context(type: ReleaseContext.self)
releaseContext.ab.getAB() //=> AB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment