使用Swift从父容器导入Objective-C供应的框架(用于混合项目)

时间:2018-12-07 21:03:15

标签: objective-c swift xcode cocoapods

我的podspec设置如下:

Pod::Spec.new do |spec|
  spec.name         = "TMGAdvertising"
  spec.default_subspecs = ["Core"]
  *** [extra stuff removed] ***

  spec.subspec 'Core' do |tmgadvertising|
    *** [extra stuff removed] ***
  end

  spec.subspec 'Inneractive' do |inneractive|
    inneractive.dependency "TMGAdvertising/Core"
    inneractive.private_header_files  = "TMGAdvertising/AdNetworkSupport/Inneractive/SDK/*.h", "TMGAdvertising/AdNetworkSupport/Inneractive/Adapters/*.h"
    inneractive.public_header_files  = "TMGAdvertising/AdNetworkSupport/Inneractive/InneractiveWrapper.h"
    inneractive.source_files  = ["TMGAdvertising/AdNetworkSupport/Inneractive/Adapters/*.{h,m,swift}", "TMGAdvertising/AdNetworkSupport/Inneractive/SDK/*.{h,m,swift}", "TMGAdvertising/AdNetworkSupport/Inneractive/InneractiveWrapper.{h,m,swift}"]
    inneractive.vendored_frameworks = "TMGAdvertising/AdNetworkSupport/Inneractive/SDK/*.framework"
    inneractive.pod_target_xcconfig = { 'OTHER_LDFLAGS' => ['-ObjC'] }
  end
end

在Obj-C(位于TMGAdvertising中)为Inneractive框架编写包装器类时,我没有问题。这是我的示例Obj-C包装器之一:

#import "InneractiveWrapper.h"
@import IASDKCore;

@implementation InneractiveWrapper

+ (void)initializeSDK:(NSString *)appId {
    [[IASDKCore sharedInstance] initWithAppID:appId];    
}

@end

问题是我不想用Objective-C编写包装程序-我更喜欢用Swift编写它们。

通常我可以使用桥接头来完成此操作(这是直接集成到应用程序中之前设置的方式),但是由于这是一个子规格,因此我无法理解。

我的问题是:有什么方法可以将这种供应商的Inneractive框架直接导入位于TMGAdvertising吊舱中的Swift文件中?

1 个答案:

答案 0 :(得分:-1)

据我所知,您应该可以在桥接头中导入文件。

@import IASDKCore;