[英]Must call a designated initializer of the superclass 'UIViewController'
I have a class A defined in ObjC and Class B - subclass of A defined in Swift. 我有一个在ObjC中定义的A类和B类-在Swift中定义的A的子类。 The implementation is as follows:
实现如下:
Class A A级
- (id)init {
return [super init];
}
Class B B级
init(url: NSURL) {
super.init()
let request = NSMutableURLRequest(URL: url)
request.setValue(valueID, forHTTPHeaderField: "value_ID")
urlRequest = request
}
convenience init(recoveryURL: NSURL) {
self.init(url: recoveryURL)
}
required public init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
Class B is initialized as follows (since its loaded from the xib file): 类B的初始化如下(因为它是从xib文件加载的):
ClassB *b = [[ClassB alloc] initWithNibName:@"ClassA" bundle:nil];
The error is seen on super.init()
line inside init(url: NSURL)
of class B. I'm trying to use convenience initializers. 在类B的
init(url: NSURL)
的super.init()
行上看到此错误。我正在尝试使用便捷初始化程序。 I would appreciate if someone can point me @ where am I going wrong? 如果有人可以指出我,我将不胜感激。
Consider putting the following code in viewDidLoad
: 考虑将以下代码放入
viewDidLoad
:
let request = NSMutableURLRequest(URL: url)
request.setValue(k_strOfferingIdValueHeader, forHTTPHeaderField: "offering_id")
urlRequest = request
It usually is the cleanest option. 它通常是最干净的选择。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.