Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Location of the generated header "MyProject-Swift.h"

I am working on a project with mixed Objective-C and Swift; I followed the "Using Swift with Cocoa and Objective-C" guide by Apple and it works great.

Out of curiosity, I would like to locate and read the generated header described in the "Mix and Match" chapter :

Objective-C and Swift Mix and Match

But I can not find it anywhere in Xcode

like image 590
Axel Guilmin Avatar asked Nov 23 '18 10:11

Axel Guilmin


People also ask

What is Swift H?

${Your project name}-Swift. h is for objc based project to use swift code I remember. It is generated by XCode, to translate swift code to a header file for objc to import. If you don't need to use swift in objc project, you don't need it.

Where is bridging header in Swift?

Alternatively, you can create a bridging header yourself by choosing File > New > File > [operating system] > Source > Header File. Edit the bridging header to expose your Objective-C code to your Swift code: In your Objective-C bridging header, import every Objective-C header you want to expose to Swift.

Are there header files in Swift?

Yes, developers do need to perform work and creating a header file of the public interface it work. It is also documentation which I guess can also be skipped since it is work. The auto-created header file does no good for Swift classes using other Swift classes.

How do I run a .h file in Swift?

You need to quote the header file name when importing it in the bridging header. Like this: #import "UIImageView+WebCache.


2 Answers

Using Finder, after a successful build in Xcode 10, the generated header can be found deep in the derived data :

~/Library/Developer/Xcode/DerivedData/ ProductModuleName-foo/ Build/ Intermediates.noindex/ ProductModuleName.build/ Debug-iphoneos/ ProductModuleName.build/ DerivedSources/ ProductModuleName-Swift.h

Where ProductModuleName is the PRODUCT_MODULE_NAME of your target and foo a seemingly random string.

like image 58
Axel Guilmin Avatar answered Oct 19 '22 14:10

Axel Guilmin


Finding the editing file

If you want to find the header file in your project, press..

cmd + shift + 0

when the search bar pops up, search for your file name

MyProject-swift.h

on the file press

cmd + shift + j

then right click and tap reveal in finder

Finding the generated file

1) Go to any objective c class where you import Myproject-swift.h

2) Then press cmd on "#import Myproject-swift.h" on top of the file

3) Click "jump to definition"

3) And there it is!

Let me know if that solves your problem!

like image 28
cevalloa Avatar answered Oct 19 '22 14:10

cevalloa