尚不支持类变量 - Class variables not yet supported

问题:

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 ? 你有解决方案吗?


解决方案:

参考: https://stackoom.com/en/question/1clS3
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章