The Swift binding uses C interop — Swift’s built-in ability to call C functions through a module map. The binding generator produces two targets that work together:Documentation Index
Fetch the complete documentation index at: https://mintlify.com/LiveSplit/livesplit-core/llms.txt
Use this file to discover all available pages before exploring further.
| Target | Contents | Purpose |
|---|---|---|
CLiveSplitCore | livesplit_core.h, module.modulemap, stub .c | Exposes the C API as a Swift module |
LiveSplitCore | LiveSplitCore.swift | Idiomatic Swift wrapper classes |
capi/bindings/swift/.
Module map
TheCLiveSplitCore/include/module.modulemap file tells the Swift compiler where to find
the C header and which system frameworks to link:
LiveSplitCore.swift begins with import CLiveSplitCore and calls the C functions directly
through this module.
Class structure
The generator produces three Swift classes per type, reflecting the Rust ownership model:Timer, Run, etc.) has a deinit that calls the C drop function. You
can also call dispose() eagerly if you want deterministic cleanup before the object is
deallocated by ARC.
Integration steps
Swift Package Manager
-
Build the static library for your target:
-
Generate the Swift bindings:
- Copy both target directories into your Swift package or Xcode project.
-
Add the static library to the linker path in your
Package.swiftor Xcode build settings.
Xcode project
- Add
capi/bindings/swift/LiveSplitCore/LiveSplitCore.swiftto your target. - Add the
CLiveSplitCorefolder (header + module map + stub.c) as a separate target or a bridging header group. - In Build Settings → Library Search Paths, add the folder containing
liblivesplit_core.a.
Example
Memory management
- The
deiniton owned classes calls the C drop function automatically when the Swift ARC reference count reaches zero. - Call
dispose()if you need the native memory freed before the Swift object is deallocated (e.g. in a tight loop). TimerRefandTimerRefMutare non-owning references — never calldispose()on them directly.- After passing an owned object to a consuming function (e.g.
Timer(run)), the binding zeroesrun.ptrso further calls onrunthrow instead of corrupting memory.