Hasty Briefsbeta

Bilingual

Integrating Zig and SwiftUI

2 days ago
  • The author advocates writing business logic in a cross-platform language like Zig and using platform-specific GUI code (e.g., SwiftUI) for a native experience, avoiding non-native solutions like Electron.
  • Key steps: export a C API from Zig, compile to a static library, merge dependencies with libtool, create a universal binary using lipo, and package as an XCFramework for Xcode.
  • The resulting XCFramework is integrated into an Xcode project by dragging it into the Frameworks section, allowing SwiftUI code to import and use the C functions.
  • The approach is standard and stable, with the author's terminal app having 94% cross-platform code in Zig/C and only 4% macOS-specific SwiftUI code.
  • The author recommends Swift over Objective-C for macOS GUI development, as modern Apple integrations rely on Swift.