Last active
February 9, 2016 10:26
-
-
Save 53ningen/6a5b42bcfda31b2d2af5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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