当我收到以下错误时,Swift 似乎无法识别 Objective-C-Header 中的 typedef:
无法从类型“MMDrawerControllerDrawerVisualStateBlock!”中找到用户定义的转换!输入“(MMDrawerController!,MMDrawerSide,CGFloat)-> Void”
我使用的是用 Objective-C 编写的MMDrawerController,但我自己的代码是用 Swift 编写的。
typedef 看起来像这样:
typedef void (^MMDrawerControllerDrawerVisualStateBlock)(MMDrawerController * drawerController, MMDrawerSide drawerSide, CGFloat percentVisible);
为了清楚起见,这里有更多代码片段:
AppDelegate.swift
func initDrawerController() {
drawerController = MMDrawerController(centerViewController: centerController, leftDrawerViewController: leftDrawerController, rightDrawerViewController: rightDrawerController)
drawerController?.setDrawerVisualStateBlock(MMDrawerVisualState.parallaxVisualStateBlockWithParallaxFactor(2.0))
}
MMDrawerController.h
typedef void (^MMDrawerControllerDrawerVisualStateBlock)(MMDrawerController * drawerController, MMDrawerSide drawerSide, CGFloat percentVisible);
@interface MMDrawerController : UIViewController
-(void)setDrawerVisualStateBlock:(void(^)(MMDrawerController * drawerController, MMDrawerSide drawerSide, CGFloat percentVisible))drawerVisualStateBlock;
@end
MMDrawerVisualState.h
@interface MMDrawerVisualState : NSObject
+(MMDrawerControllerDrawerVisualStateBlock)parallaxVisualStateBlockWithParallaxFactor:(CGFloat)parallaxFactor;
@end
模块-桥接-Header.h
#import "MMDrawerController.h"
#import "MMDrawerVisualState.h"
在构建这个时,我在我的 AppDelegate 中为 Expression with 收到一个错误setDrawerVisualStateBlock
,尽管在 中有一个 typedef MMDrawerController.h
:
这是一个错误(因为在 Objective-C 上,它工作正常)?或者有没有人知道/知道如何处理它?非常感谢您的帮助,谢谢!