Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Swift, how to import a target with dash in its name?

Tags:

macos

ios

swift

This might be something very basic yet I just can't find the answer...

Say I have two targets in my Xcode project: foo-bar and foo-barTests

now if I want to make an identifier from foo-bar visible in foo-barTests, how do I import it?

like image 488
Metaphox Avatar asked Sep 24 '14 08:09

Metaphox


People also ask

How do I import an Objective-C file into Swift?

To import a set of Objective-C files into Swift code within the same app target, you rely on an Objective-C bridging header file to expose those files to Swift. Xcode offers to create this header when you add a Swift file to an existing Objective-C app, or an Objective-C file to an existing Swift app.

What does import Foundation do in Swift?

When importing Foundation (or anything else like Cocoa or UIKit that will import it implicitly) Swift automatically converts some Objective-C types to Swift types, and some Swift types to Objective-C types, and a number of data types in Swift and Objective-C can be used interchangeably.

What is product module name?

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.


1 Answers

Okay it was very basic:

Naming Your Product Module

The name of the Xcode-generated header for Swift code, and the name of the Objective-C bridging header that Xcode creates for you, are generated from your product module name. By default, your product module name is the same as your product name. However, if your product name has any non-alphanumeric characters, such as a period (.), they are replaced with an underscore (_) in your product module name. If the name begins with a number, the first number is replaced with an underscore.

You can also provide a custom name for the product module name, and Xcode will use this when naming the bridging and generated headers. To do this, change the Product Module Name build setting.

so import foo-bar becomes import foo_bar .

like image 187
Metaphox Avatar answered Sep 18 '22 19:09

Metaphox