0
votes

I want to create a custom framework using Swift. There're some Swift files in the framework, then I create a new Objective-C file named A (A.h and A.m).

Within this Objective-C file, I want to use another Swift class so I add a following import statement on the top of the A.m file

#import "<My framework target name>-Swift.h" 

When building framework, I got error that indicates '-Swift.h' not found.

I worked around some solutions but still get stuck

  • I add an bridging header file but failed due to custom framework not allows bridging header.
  • I turned on 'Defines Module' to YES on Build Settings but seems useless.
  • Adding '$(CONFIGURATION_TEMP_DIR)/Product Name With Spaces.build/DerivedSources' to Header Search Path doesn't help.(following this thread iOS - 'MyProject-Swift.h' file not found when running Unit Tests for Swift , @gagarwal 's answer)

  • I also tried to move the import statement to umbrella header, but the same error occurs.

How can I use Swift class in the Objective-C file?

1

1 Answers

0
votes

The format of your #import statement is how you include the bridging header in an Objective-C file in an application target.

In an Objective-C file inside a framework target, to import the Swift interface your import statement needs to look like this:

#import <FrameworkProductName/FrameworkProductModuleName-Swift.h>

Also, remember that in a framework target, you have to make classes and properties you want to accessible from Swift public or open, in addition to @objc where necessary.