4

I have created an open source library (https://github.com/linkedin/LayoutTest-iOS) which has two Cocoapods inside - LayoutTest and LayoutTestBase. LayoutTest depends on LayoutTestBase and one of the .h files needs to import something from LayoutTestBase. Currently, I do this using:

@import LayoutTestBase;

However, this only works if the application uses use_frameworks! in their Podfile. Some apps do not want to use this cocoapods option. Without use_frameworks!, it works if I use:

#import <LayoutTestBase/LYTLayoutPropertyTester.h> // OR
#import "LYTLayoutPropertyTester.h"

However, when using this with use_frameworks!, it gives the error: "Include of non-modular header inside framework module 'LayoutTest.LYTLayoutTestCase'"

Clearly, there should be a way of doing this import regardless of whether the user uses use_frameworks! or not in their Podfile. How can I get this library to compile and run correctly?

Research

I've looked on stackoverflow, and this seems to be the most similar question: CocoaPods framework with dependencies - include of non-modular header inside framework module. It mentions that it's a problem with the Parse library, but doesn't mention how it needs to be fixed. Since I own the dependency, I can fix this. I've also tried setting Allow non-modular frameworks to YES in all settings (projects, unit tests, all pods, etc), and this doesn't seem to do anything.

To Reproduce

Create a new project. Add this Podfile:

target :'{MyAppTarget}Tests' do
pod 'LayoutTest'
end

Run pod install. Try to run unit tests on the app. It will fail. Now, try changing LYTLayoutTestCase.h to use #import <LayoutTestBase/LYTLayoutPropertyTester.h>. It now works. However, if you add use_frameworks! to the Podfile, it no longer works.

Community
  • 1
  • 1
plivesey
  • 2,337
  • 1
  • 16
  • 18

1 Answers1

0

I don't think this is the optimal solution but the work around I found was to do an #if __has_include and do both solutions depending on whether it was built with use_frameworks!

Here's a link to the github issue with more details: https://github.com/linkedin/LayoutTest-iOS/issues/8

If anyone knows how libraries like parse-SDK do it without these workarounds, I'm still interested.

plivesey
  • 2,337
  • 1
  • 16
  • 18