mirror of
https://github.com/logos-messaging/nim-ffi.git
synced 2026-06-21 08:49:34 +00:00
A SwiftPM package wrapping the timer library's native ABI behind an idiomatic `TimerNode` Swift class. `build-xcframework.sh` cross-compiles the Nim library to a static MyTimer.xcframework with three slices — ios-arm64 (device), ios-arm64-simulator, and macos-arm64 — assembling the .xcframework by hand so it works without a functioning Simulator toolchain (CI-friendly). The wrapper bridges the async FFI-thread callback to a synchronous Swift API with a semaphore and reads the typed EchoResponse struct out of the callback. The macos-arm64 slice makes the wrapper testable on the host: `swift test` passes against it. Device/simulator slices are the real iOS deployment artifacts. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
23 lines
667 B
Swift
23 lines
667 B
Swift
import XCTest
|
|
@testable import MyTimer
|
|
|
|
final class MyTimerTests: XCTestCase {
|
|
func testCreateVersionEcho() throws {
|
|
let node = try TimerNode(name: "ios-demo")
|
|
|
|
XCTAssertEqual(try node.version(), "nim-timer v0.1.0")
|
|
|
|
let r = try node.echo("hello from Swift", delayMs: 2)
|
|
XCTAssertEqual(r.echoed, "hello from Swift")
|
|
XCTAssertEqual(r.timerName, "ios-demo") // proves the lib's own state round-tripped
|
|
}
|
|
|
|
func testManyEchoes() throws {
|
|
let node = try TimerNode(name: "loop")
|
|
for i in 0..<200 {
|
|
let r = try node.echo("m\(i)")
|
|
XCTAssertEqual(r.echoed, "m\(i)")
|
|
}
|
|
}
|
|
}
|