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 :
But I can not find it anywhere in Xcode
${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.
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.
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.
You need to quote the header file name when importing it in the bridging header. Like this: #import "UIImageView+WebCache.
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.
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
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With