Can't access Swift class from Objective-C & Swift mixed static framework

Hi, there.

I built an OC&Swift mixed static framework with CocoaPods
-packager
. I also built a host project and integrate the static framework via CocoaPods. which pod file looks like this:

plugin 'cocoapods-binary-source-switcher', :all_binary => true
use_frameworks! :linkage => :static
platform :ios, '10.0'
target 'MyMixedPod_Example' do
    pod 'SomePod', '0.1.0'
end

There is a class named SomeClass in the mixed framework, it's very simple:

    public class SomeClass: NSObject {
    @objc public var name: String! 
    @objc public func test() {
        print("Hello \(self.name ?? "Swift")")
       }
    }

In my host project, I try to access the SomeClass, an error comes, Use of undeclared identifier 'SomeClass',

@import SomePod; // import mixed module
...
- (void)viewDidLoad
{
    [super viewDidLoad];
    SomeClass *cls = [SomeClass new];
}

As the apple documentation said:

To import a set of Swift files in the same framework target as your Objective-C code, import the Xcode-generated header for your Swift code into any Objective-C .m file where you want to use your Swift code.

So I try to import the module_name-Swift.h file manually but still failed.

#import < SomePod-Swift.h>. // error 'SomePod-Swift.h'file not found
#import < SomePod/SomePod-Swift.h> //warning Missing submodule 'SomePod. SomePod_Swift'

But when I tried to integrate the pod as dynamic framework or source code instead, it works, I'm confused. Why?

1 Like