子类化ViewController Swift

时间:2015-10-11 16:34:15

标签: swift2 subclassing

很抱歉,如果之前已经问过这个问题..我没有找到它就看了。

我正在使用Swift2构建IOS应用程序。我有一个很长的主类(ViewController:UIViewController)。

我试图通过在另外两个新类Customer:Viewcontroller和Server:ViewController中继承视图控制器来重新组织我的代码。

我的目标是这两个类被执行添加扩展功能给我viewcontroller,扩展对我没用,因为我重写了子类。

如何在app推出时执行这些类。

现在我的代码组织得像这样......

//ViewController handling now almost all my code
class ViewController: UIViewController,UIImagePickerControllerDelegate,MPCManagerDelegate,UITableViewDelegate,UITableViewDataSource,UINavigationControllerDelegate {

///some variables 

override func viewDidLoad() {
    super.viewDidLoad()
////some other stuff
}
///some other functions
}



///Server subclass My goal is to print ("subclassing after view controller 's didload function

class server:ViewController {



override func viewDidLoad() {
    super.viewDidLoad()
    print ("loaded extern class")
}
}

提前致谢

1 个答案:

答案 0 :(得分:0)

您可以在Swift中继承其他类,如下所示:

var subclassedServer = server()

要访问其中的任何变量,请执行以下操作:

subclassedServer.somethingelse = value
祝你好运!