問題:
I begin my project with a split view controller as initial view controller and start it automatically from storyboard. 我使用拆分視圖控制器作爲初始視圖控制器開始我的項目,並從故事板自動啓動它。
Generally, an app with this UI have one and only one split view controller as root, so I create a static variable in the subclass and set it when initialisation was done. 通常,具有此UI的應用程序只有一個拆分視圖控制器作爲root,因此我在子類中創建一個靜態變量 ,並在初始化完成後設置它。
So I want try this behaviour with swift. 所以我想用swift試試這個行爲。
I read the Swift programming language guide book on iBook about Type properties (with static and class keyword) and trying a piece of code to the job: 我在iBook上閱讀了關於Type屬性(帶有static和class關鍵字)的Swift編程語言指南,並嘗試了一段代碼:
import UIKit
class SplitViewController: UISplitViewController {
class func sharedInstance() -> SplitViewController {
return SplitViewController.instance
}
class let instance: SplitViewController = nil
init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
self.initialization()
}
init(coder aDecoder: NSCoder!) {
super.init(coder: aDecoder);
self.initialization()
}
func initialization() {
SplitViewController.instance = self;
}
}
but I figured out when Xcode say the class keyword for type properties wasn't supported yet. 但是當Xcode說不支持類型屬性的class關鍵字時,我想通了。
Did you have a solution to do this ? 你有解決方案嗎?