I have an old Objective-C project, which has multiple targets, and some of the targets share a framework (let's call it CJDataKit) that's also written in Objective-C. I'm trying to add some Swift code to my project, at least to the main app target, and have some limited implementation of it working, but I'm running into some issues whenever the Swift code needs to use or import the CJDataKit framework, or any header file that itself imports the CJDataKit framework.
What's Working
- I wrote a basic UIView subclass in Swift (which didn't need any other code from my app), and I can use this in my Objective-C target, using @objc keyword and by importing "MyApp-Swift.h" in my Objective-C code.
- I then wrote a new UIViewController subclass in Swift, and used a couple of simple Objective-C objects from both CJDataKit framework and non-framework classes. I did this by creating a bridging header file, and added the Objective-C headers there.
So far so good, and everything compiles fine.
What's Not Working
The problem happens if I try to import into Swift other Objective-C files that might be importing the CJDataKit framework inside it. For e.g. I wanted to write a Swift extension of an existing UIViewController subclass (call is PageAViewController). This PageAViewController imports multiple other header files. If I add it to the bridging header file, I start getting build errors:
Include of non-modular header inside framework module 'CJDataKit': '.../CJDataKit/Person.h'
Commenting out the
@import CJDataKit
makes it work for this particular file, but it still gets compile errors from a different header file (that was imported by PageAViewController). It only seems to work if all the files listed in the bridging-header file don't have a
@import CJDataKit
, which is difficult and cumbersome. So something about Swift doesn't like interacting with the CJDataKit framework directly.
I've also tried importing the CJDataKit.h header file into the Swift bridging header file, figuring this way I don't have to individually import each file from the framework, but that doesn't work either. That results in a different error:
Could not build module 'CJDataKit.h'
I've tried using
#import <CJDataKit/CJDataKit.h>
as well but same result.
From my settings:
- "Allow Non-modular Includes In Framework Modules" is Yes on the target, and framework. It is No at the project-level.
- "Defines Module" is also set to Yes, on both the app target and framework, and No at project-level.
Would love some help in getting this setup correctly. I've been searching for a solution, but haven't really found anything.