Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Behaviour of "Defines Module = Yes" for testing a project

Tags:

My Swift/Obj-C hybrid project is setup with two targets:

MyProject and MyProjectTests

In order to write unit tests (using XCTest), I have the following configurations for the main target (MyProject) build settings:

Enable testability = Yes
Defines module = Yes

This works fine, but I would like to know what is actually going on when I specify Defines module = Yes.

Does specifying Defines module = Yes mean:

  • A framework is created for the target, or at least a module map, or an umbrella header for the target?
    • If it's this case, i.e. there are at least temporary build files generated to make the main target look like a module, then where are they usually located? In DerivedData?
  • Or does Xcode have some special treatment for the main project target, such that turning on the Defines Module = Yes flag does nothing filesystem-wise, but still allows the main project target to be imported as a (testable) module in a test target?
like image 694
peco Avatar asked Aug 20 '18 08:08

peco


1 Answers

Making app work with both Swift and Objective-C, can be a delicate process. You must adopt modules if you want a hybrid project. When bringing old Objective-C code to a Swift project, this means setting the “Defines Module” (DEFINES_MODULE) build setting to YES in the framework target. This instructs Xcode to install a module.modulemap file (and possibly a module.private.modulemap) alongside the headers in the framework. Objective-C frameworks need to define a module to be used by Swift.

Source: Big Nerd Ranch

like image 88
Andrei Konstantinov Avatar answered Oct 04 '22 15:10

Andrei Konstantinov