我想创建,我可以在我的应用程序使用一个定制的框架。当我在应用程序中从我的框架实例化我的第一个ViewController
时,我想传入两个参数。的iOS:将参数传递给私人框架,同时初始化一个UIViewController
import UIKit
public class NewVC: UIViewController {
public var startColor: String?
public var endColor: String?
public required init(startColor: String, endColor: String) {
self.startColor = startColor
self.endColor = endColor
super.init(nibName: "sb", bundle: nil)
}
public required init?(coder aDecoder: NSCoder) {
super.init(coder:aDecoder)
}
}
现在,我想在实例NewVC
我AppDelegate
:
import NewVCFramework
//...
let vc = NewVC(startColor:"00ff33a", endColor:"ff0c756")
let s = UIStoryboard(name: "sb", bundle: NSBundle(forClass: vc))
//I get an error on the line above that points at vc
self.window?.rootViewController = s.instantiateInitialViewController()
下面是我的错误:
Error: Cannot convert value of type 'NewVC' to expected argument type 'AnyClass' (aka 'AnObject.Type')
看看这个http://stackoverflow.com/questions/33567189/self-type-不能待直接转换到anyclass-在延伸到目标-CC – sschale