Using C Libraries in Swift 3
summary
Builds a working Swift 3 wrapper around an existing C library and shows the exact steps that make it work: create module maps to expose headers, call C functions and map structs and pointers to UnsafePointer/UnsafeBufferPointer, convert String <-> C by utf8 and null termination, manage ownership and lifetimes, and pass Swift closures through C callbacks via Unmanaged/opaque context pointers. Demo compiles, prepares statements, binds values, reads results from a decades‑long weather DB and plots a surprising ~350 days/year with essentially no snow.
AI-written summary · about
chapters (17)
- 0:00Intro
- 1:06Advantages of C
- 2:19Modules
- 2:59Module maps
- 4:03One module map per SDK
- 4:48No expectation of privacy
- 8:47C functions
- 9:32C Structs
- 11:20UnsafeBufferPointer
- 14:29C Strings in Swift
- 14:49Swift strings
- 23:47Ownership
- 27:02Re-binding memory
- 27:52Memory layout
- 30:18Prefer ARC!
- 33:25Context pointers
- 40:23Resources








