DAY #7

Swift is interoperable with Obj-C and C.

This is a really cool feature that allows you to make lightning fast code.

With a little (lot) of finagling, you can run C libraries from Swift, which opens the doors to higher performance and graphical/musical/computational applications.

The basic structure for importing a C library in Swift might look like this:

Compiled C library on system in users/lib or wherever it is default -> Make a module -> Import as system library with SwiftPM (SwiftPackageManager) into that module -> Make sure linker is working correctly -> Create modulemap file and Bridging header file (also sometimes called a shim) -> Configure these files -> Import this module into your project using SwiftPM.

It is very difficult since SwiftPM does not tell you what you are doing wrong, and there is not a lot of good help online.

Originally published 04/09/2021 @ https://pittcsc.org/ Discord

Published here on 09/08/2022. Blog published date reflects the original date of publication.