I have the following
- A 3rd party xcframework (
ThirdPartyFramework) - A private pod (written in Swift) that wraps the above xcframework (
AdditionalSDK) - The main SDK pod, also written in Swift (
MainSDK) - A project (
MyProject)
What I want to achieve is MainSDK to use functionality from AdditionalSDK, if AdditionalSDK is present. If not, MainSDK should continue to work without the AdditionalSDK's functionality.
After digging around I stumbled into this question, which led me to this guide. I've tried other guides as well, without any luck. I've also noticed that in the original question, each podspec defines a vendored framework (Firebase, Facebook and other major SDKs also do the same). In my case only the AdditionalSDK defines a vendored framework. The MainSDK defines its source files (along with headers, modulemap, etc).
The #if canImport(AdditionalSDK) didn't work for me, as the guide also states. I then tried to implement Obj-C interoperability classes. I.e. I added AdditionalSDKInterop.{h,m} as below
// AdditionalSDKInterop.h
#import <Foundation/Foundation.h>
#import <MainSDK/MainSDK-Swift.h> // <-- First problem here
@interface AdditionalSDKInterop : NSObject
@property (weak, nonatomic) id<MainSDKInteropDelegate> delegate;
+ (BOOL)isModuleAvailable;
@end
// AdditionalSDKInterop.m
#import "AdditionalSDKInterop.h"
@import AdditionalSDK; // <-- Second problem here
@implementation AdditionalSDKInterop
+ (BOOL)isModuleAvailable {
if ([AdditionalSDK class]) {
return YES;
} else {
return NO;
}
}
@end
The MainSDKInteropDelegate is a protocol in the MainSDK, which defines the methods that can be called from the AdditionalSDK.
@objc public protocol MainSDKInteropDelegate: class {
@objc func initializeSDK()
}
My first problem is that I get MainSDK/MainSDK-Swift.h file not found in the AdditionalSDKInterop.h, but strangely not always. Bear in mind that I clean my project and I delete the Derived data prior to each build. Still, sometimes I get this error, sometimes not. My second problem is that I get Module AdditionalSDK not found, if I don't add pod 'AdditionalSDK' in the project's podfile.
What am I missing, any thoughts?