27

The title says it all. I've searched in the build settings for SWIFT_MODULE_NAME, and nothing came up. I've also searched online, and there are references to this name, but there is no information on how it is defined. Furthermore, I couldn't find any mention of SWIFT_MODULE_NAME in the Apple Docs.

I do know this: it is used in the "Objective-C Generated Interface Header Name" build setting, and can be viewed by double-clicking on the settings value:

$(SWIFT_MODULE_NAME)-Swift.h

It is used to bridge the gap between Objective-C and Swift, and appears only for projects that include Swift files, (along with Objective-C files I presume). As of this posting, Xcode 7.3 is the latest and greatest.

But, where is this value defined, and how do I modify it?

Sheamus
  • 6,506
  • 3
  • 35
  • 61
  • 2
    Have you checked out this doc: https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html#//apple_ref/doc/uid/TP40014216-CH10-ID138 ? usually it is your product name. You can set change the value in "Product Bundle Identifier" in Build Settings. Note you can not override a product name in a Framework – Zhao Apr 14 '16 at 00:34
  • Yes that's helpful, thanks. From that doc: "Xcode uses your product module name (PRODUCT_MODULE_NAME)—not your target name (TARGET_NAME)—when naming the Objective-C bridging header and the generated header for your Swift code." – Sheamus Apr 14 '16 at 00:52

4 Answers4

51

The module name comes from the Product Module Name build setting:

build settings screenshot

The SWIFT_MODULE_NAME setting is apparently hidden, but you can see its derivation by looking at Xcode.app/Contents/PlugIns/Xcode3Core.ideplugin/Contents/SharedSupport/Developer/Library/Xcode/Plug-ins/XCLanguageSupport.xcplugin/Contents/Resources/Swift.xcspec:

...
{
    Name = "SWIFT_MODULE_NAME";
    Type = String;
    DefaultValue = "$(PRODUCT_MODULE_NAME)";
    CommandLineArgs = (
        "-module-name",
        "$(value)",
    );
},
...
jtbandes
  • 115,675
  • 35
  • 233
  • 266
  • 1
    Thank you, that's it! I changed the PRODUCT_MODULE_NAME, and the SWIFT_MODULE_NAME was updated! – Sheamus Apr 14 '16 at 00:46
  • 1
    Oh my, 4 hours looking for this - debated the concept of retirement. Xcode Version 9.4 (9F1027a) had filled it blank from a fresh swift project create 3 days ago. I will post a possible bug. ouch! don't forget #import "MsbHrv-Swift.h" in the .m, for every function on swift object that your accessing put the "@objc" in front of the declaration in the .swift file, and make sure this SWIFT_MODULE_NAME is set in the PRODUCT_MODULE_NAME. OR just build everything in swift, be happy, and pet puppies to calm your day. – Matthew Ferguson Jun 11 '18 at 04:51
  • 1
    Please note that Product Module Name defaults to using ```$(PRODUCT_NAME:c99extidentifier)``` so the best place to change this is to ensure that you set PRODUCT_NAME or "Product Name" to a value and all will update accordingly. – Dino Alves Sep 26 '18 at 09:45
  • To follow up on Dino's observation: There's yet another step, because PRODUCT_NAME is defined as $(TARGET_NAME). But... it dead-ends there. I can't find TARGET_NAME in any of the settings; maybe Xcode only shows it in the project navigator (left pane). One more thing: If your project or product name is hyphenated, Xcode will replace the hyphen with an underscore. This will cause builds to fail if you explicitly refer to the $(SWIFT_MODULE_NAME)-Swift.h file's expected name anywhere. – Oscar May 07 '19 at 20:50
8

SWIFT_MODULE_NAME, PRODUCT_MODULE_NAME, PRODUCT_NAME, EXECUTABLE_NAME

Default values:

EXECUTABLE_NAME = $EXECUTABLE_PREFIX$PRODUCT_NAME$EXECUTABLE_SUFFIX
SWIFT_OBJC_INTERFACE_HEADER_NAME = $(SWIFT_MODULE_NAME) 

SWIFT_MODULE_NAME = $(PRODUCT_MODULE_NAME)
PRODUCT_MODULE_NAME = $(PRODUCT_NAME:c99extidentifier)
PRODUCT_NAME = $(TARGET_NAME:c99extidentifier)

Observation:

SWIFT_MODULE_NAME == PRODUCT_MODULE_NAME

c99extidentifier

Xcode is able to substitute a value of variable c99extidentifier identifier which supports extended characters from C99

//for example
PRODUCT_NAME = My Framework
PRODUCT_MODULE_NAME = $(PRODUCT_NAME:c99extidentifier) = My_Framework

EXECUTABLE_NAME name of binary

Product Module Name(PRODUCT_MODULE_NAME) determines how the import statement will look like. For example when you are creating a Library or a Framework.

Using:

//Objective-C
@import module_name; 

//Swift
import module_name 

Product Name(PRODUCT_NAME) determines the name of binary. E.g. MyFramework.framework

[TARGET_NAME]

Rule is:

SWIFT_MODULE_NAME should equal to PRODUCT_MODULE_NAME

[Custom .modulemap]

yoAlex5
  • 29,217
  • 8
  • 193
  • 205
6

Go to build Settings and click + next to 'Levels'. See :

enter image description here

replace NEW_SETTING as SWIFT_MODULE_NAME for the name of the setting, and whatever is the module name for .h file (No spaces, please) goes on the right.

Anton Tropashko
  • 5,486
  • 5
  • 41
  • 66
0

Have you checked out this doc: developer.apple.com/library/ios/documentation/Swift/Conceptual/… ? usually it is your product name. You can set change the value in "Product Bundle Identifier" in Build Settings. Note you can not override a product name in a Framework

See the screenshot:

enter image description here

Zhao
  • 904
  • 1
  • 11
  • 34