目标C前向声明的协议方法类型在Swift上不可用

时间:2017-10-12 14:33:37

标签: objective-c swift cocoa-touch protocols

我有以下Objective C类标题:

@protocol CustomKeyboard;
@class CustomKeyboardView;
@protocol CustomKeyboardViewProtocol <NSObject>

- (void)customKeyboardView:(UIView<CustomKeyboard> *)customKeyboard  numberPress:(UIButton *)sender;

@end

@protocol CustomKeyboard <NSObject>

@required

-(id)initWithDelegate:(id<CustomKeyboardViewProtocol>)delegate;
-(void)reload;

@property (nonatomic, weak) UITextField * textField;
@property (nonatomic, weak) id<CustomKeyboardViewProtocol> delegate;

@end

@interface CustomKeyboardView : UIView <CustomKeyboard>
{
    IBOutlet UIView *keyboardView;
}

- (void)hide;
- (void)show;

@end

Swift中的这个类正在尝试采用该协议,但我收到的方法中的类型错误,并且自动完成已经消失:

extension MyViewController: CustomKeyboardViewProtocol {

    func customKeyboardView(_ customKeyboard: UIView!, numberPress sender: UIButton!) {
    }

}

错误说:

Candidate has non-matching type '(UIView!, UIButton!) -> ()'

任何线索,如果错误是因为协议中的循环依赖还是关于类型?我刚刚更新到Xcode 9和Swift 4,并更新到推荐的设置,它曾经工作得很好。

0 个答案:

没有答案