如何在 Xcode Objective-C Project 中的 .mm 类扩展中导入/使用 swift 静态库/框架



需要在 c++/.mm 类文件中导入 swift 框架类

以下是头文件中TargetsDefinedViewController.h语句声明

    #import<MaterialShowcase/MaterialShowcase.h>
 @interface TargetsDefinedViewController ()<MaterialShowcaseDelegate>
 @end

MaterialShowcase是一个快速的项目。要在Objective-C中使用它,我们必须构建框架,然后将其集成到Project中。 TargetsDefinedViewController实现文件扩展名为 .mm

错误:找不到"材料展示委托"的协议声明

您不能将 swift 类文件直接导入到 Objective-C .m 文件中,因为 MaterialShowcase 是.swift文件,并且您 #import"<"MaterialShowcase/MaterialShowcase.h>"的第一行。 所以这是错误的。

您可以导入 #import"APPNAme-Swift.h",用于TargetsDefinedViewController的.m文件,并且它正在工作,请尝试一下。

最新更新