迅速3 - 方法不会覆盖自其超

问题描述:

我试图重写在斯威夫特子类的MyMethod任何方法,但不断收到以下错误:迅速3 - 方法不会覆盖自其超

method does not override any methods from its superclass

ViewControllerA.h

@interface ViewControllerA : UIViewController 
    // define a bunch of properties and methods 
    // note: myMethod is NOT included in this interface 
@end 

ViewControllerA.m

@implementation ViewControllerA 
    (void)myMethod:(ParameterClass *)parameter { 
     ... 
    } 
@end 

ViewControllerB.h

@interface ViewControllerB : ViewControllerA 
    // define a bunch of properties 
@end 

ViewControllerB.m

@implementation ViewControllerB 
    // define a bunch of methods 
@end 

ViewControllerC.swift

class ViewControllerC: ViewControllerB{ 
    override func myMethod(parameter: ParameterClass) { // ERROR is here 
     NSLog("Calling overrided myMethod") 
    } 
} 

有人可以告诉我是什么我丢了?

+1

也许是因为'myMethod的:'是不公开? – rmaddy

+0

谢谢你们,那就是问题所在。我认为超类的方法可用于子类,因此需要被覆盖。如果你们想发布解决方案,我会接受。再次感谢! – Vee

斯威夫特只能看到头文件,你在桥接报头包括 - 如果你不包括在@interfaceViewControllerA您的方法声明,有没有办法让斯威夫特知道这件事。

所以,只要把它放在你的@interface

@interface ViewControllerA : UIViewController 

// By default it will be imported into Swift as myMethod(_:). Adding NS_SWIFT_NAME 
// allows you to change that to whatever you want. 
-(void)myMethod:(ParameterClass *)parameter NS_SWIFT_NAME(myMethod(parameter:)); 

@end