This post also has a good explanation regarding how to do this using clang's module support.
It's framed in terms of how to do this for the CommonCrypto project, but in general it should work for any other C library you want to use from within Swift.
I briefly experimented with doing this for zlib. I created a new iOS framework project and created a directory zlib, containing a module.modulemap file with the following:
module zlib [system] [extern_c] {
header "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/zlib.h"
export *
}
Then under Targets -> Link Binary With Libraries I selected add items and added libz.tbd.
You may want to build at this point.
I was then able to write the following code:
import zlib
public class Zlib {
public class func zlibCompileFlags() -> UInt {
return zlib.zlibCompileFlags()
}
}
You don't have to put the zlib library name in front, except in the above case I named the Swift class func the same as the C function, and without the qualification the Swift func ends up being called repeatedly until the application halts.