1

I have written a framework in Swift 2.3 that uses Cocoapods to utilize a few Objective-C projects such as AFNetworking and CocoaLumberjack. Since bridging headers cannot be used in frameworks I have defined module maps for each Objective-C project (as well as for a few objective-c utiltities I have written). For example, the module.modulemap for AFNetworkModule looks like:

module AFNetworkModule {
  header "../../Pods/Headers/Public/AFNetworking/AFNetworkReachabilityManager.h"
  export *
}

Also added the path to modulemaps in the Build Settings -> Import Paths. This way I can import the modules in my framework swift code:

import AFNetworkModule

The setting Defines Module is set to Yes in the Build Settings for the framework.

Externally I can use the framework without any problems in my sample Swift app using import MyFramework when both the framework and the sample app are in the same workspace:

-- SampleAppProj
-- MyFrameworkProj
-- Pods

But I get "Cannot load underlying module for MyFramework" when trying to import the framework in a separate Swift project. The generated framework contains a Headers folder containing MyFramework-Swift.h and MyFramework.h (the umbrella file). I have not added any headers to the umbrella file as I am using modules to import objective-c internally in the swift framework.

sigrem
  • 57
  • 1
  • 5
  • 1
    If you're using cocoapods, it automatically creates modules for your pods, so I'm confused why you need to create module maps. Can you explain that part in more detail? – Dave Weston Feb 28 '17 at 00:47
  • When you use Objective-C pods in a Swift project, as this case, you also use the bridging header to include the header files but bridging header is not allowed in frameworks. The only way I know is using module maps. Would be great to know if there are other options. – sigrem Feb 28 '17 at 15:10
  • 2
    You shouldn't need a bridging header to include the header files, you just need to import the framework that the pod defines, like `import AFNetworking`. Is cocoapods generating frameworks for you? I assume you have `use_frameworks!` in your Podfile? – Dave Weston Feb 28 '17 at 18:05
  • 1
    Unfortunately I cannot have `use_frameworks!` in my Podfile due to other issues (related to use of a google api in the podfile). – sigrem Feb 28 '17 at 19:24
  • Also, apart from how the module maps are created, it looks like `import MyFramework` in the sample app makes the framework accessible if the sample app is in the same workspace but not if imported in a separate project. Any way to know what "underlying module" Xcode cannot load? – sigrem Mar 01 '17 at 15:03
  • 1
    You can look at the full build logs: http://stackoverflow.com/questions/19014359/how-do-i-view-the-full-build-log-on-xcode5 and see if that gives you any insight. – Dave Weston Mar 01 '17 at 23:07
  • Thanks Dave for the link. – sigrem Mar 03 '17 at 17:03
  • @daveWeston, you could add `use_frameworks!` as an answer, and I'll gladly upvote it. It worked for me. Thank you! – Nikola Markovic Aug 22 '21 at 19:19

1 Answers1

1

I had the same problem suddenly popping up regarding the AVFoundation module, on an app that was perfectly compiling till then. As a workaround, unchecking Show live issues in Xcode -> Settings -> General allows to avoid this error and to compile.

Edit: Adding the module to the project settings fixed the issue. See answers to this question.

J Kasparian
  • 465
  • 2
  • 7