Last active
September 19, 2015 23:50
-
-
Save xenophy/9a912ec6237be9b8fe06 to your computer and use it in GitHub Desktop.
Create dynamic class instance from String in Swift 2.0
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
// 実行アプリ名前空間取得 | |
let namespace = NSStringFromClass(self.dynamicType).componentsSeparatedByString(".")[0] | |
// 生成クラス名取得 | |
let clsName = namespace + ".MyViewController" | |
// ViewController生成 | |
var cls:UIViewController.Type = NSClassFromString(clsName) as! UIViewController.Type | |
var vc:UIViewController = (cls.init() as UIViewController) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment