Oscar Franco

Swift 5.9 Notes

Nov 2023

Swift 5.9 has enabled direct interop with C++. This means you can directly call and interact with C++, as well as introduced a series of objects that allow to interact with integral and C++ class values directly (e.g. std::string).

In order to enable the C++ interop, you need to be on XCode 15 (I think), and your projects needs to be Swift enabled. If you are not sure, you only need to add a Swift file and the bridging header will be created for you and all the Swift build settings will be enabled on XCode.

Afterwards you need to go into the Build SettingsSwift Compiler - LanguageC++ and Obj-C++ Interoperability and change the value from C to C++

If you want to do the same in a CocoaPods project you need to modify the pod config like this:

s.pod_target_xcconfig = {

Clang has issues with headers (it generates a module map, topic for another day). Instead of importing headers directly from your dependency, you should import the umbrella header.

#import <jsi/jsi.h>

You should import everything with

#import <mypod-umbrella.h>

Afterwards you are in the clear, you should be able to call any C++ function/class from your Swift code and viceversa.