1
如何將的initWithDevice函數改寫爲MyViewControllerB轉換爲Swift 3?將Obj-C初始化覆蓋函數轉換爲Swift 3
MyViewControllerA
@interface MyViewControllerA : UIViewController
- (instancetype)initWithDevice:(DeviceClass *)device;
@end
@implementation MyViewControllerA
- (instancetype)initWithDevice:(DeviceClass *)device
{
self = [super init];
if (self) {
// set a bunch of properties
}
return self;
}
@end
MyViewControllerB
@interface MyViewControllerB : MyViewControllerA
- (instancetype)initWithDevice:(DeviceClass *)device;
@end
@implementation MyViewControllerB
- (instancetype)initWithDevice:(DeviceClass *)device
{
if (self = [super initWithNibName:@"AnotherViewController" bundle:nil]) {
// init stuff for subclass
}
return self;
}
@end
試試這個http://objc.to/jlzy3h –
試試這個https://objectivec2swift.com/ #/ home/converter/ –
謝謝,夥計們!漂亮的工具。 @AntonyRaphel - 我也不得不增加以下內容: 所需的init(編碼器aDecoder:NSCoder){ super.init(編碼器:aDecoder) } 如果你想發佈的解決方案,我會接受?謝謝! – Vee