| 1 | # Onde example app |
| 2 | |
| 3 | A one-screen SwiftUI chat app. Loads an LLM on your iPhone and streams replies, all on-device. |
| 4 | |
| 5 | ## Setup |
| 6 | |
| 7 | Install [XcodeGen](https://github.com/yonaskolb/XcodeGen) if you don't have it: |
| 8 | |
| 9 | ``` |
| 10 | brew install xcodegen |
| 11 | ``` |
| 12 | |
| 13 | From the `onde-swift` repository root, build the local Onde XCFramework for iOS: |
| 14 | |
| 15 | ``` |
| 16 | make ios |
| 17 | ``` |
| 18 | |
| 19 | This regenerates `Sources/Onde/onde.swift` from your local Rust build in `../onde` and writes `OndeFramework.xcframework` into the package root so SwiftPM can link it. |
| 20 | |
| 21 | Then generate the Xcode project and open it: |
| 22 | |
| 23 | ``` |
| 24 | cd Examples/OndeExample |
| 25 | xcodegen generate |
| 26 | open OndeExample.xcodeproj |
| 27 | ``` |
| 28 | |
| 29 | Set your development team under Signing & Capabilities, pick your iPhone or simulator, hit Run. |
| 30 | |
| 31 | ## What it does |
| 32 | |
| 33 | On first launch, it downloads and loads the default model for your device (Qwen 2.5 Coder 1.5B on iPhone, 3B on Mac). After that you can chat with it. |
| 34 | |
| 35 | Current example app features: |
| 36 | |
| 37 | - token-by-token streaming with a stop button |
| 38 | - local conversation persistence between launches |
| 39 | - model settings sheet for system prompt + sampling preset |
| 40 | - toolbar actions to reload the model or clear the conversation |
| 41 | - prompt suggestions when the conversation is empty |
| 42 | |
| 43 | ## Files |
| 44 | |
| 45 | | File | What's in it | |
| 46 | |------|-------------| |
| 47 | | `App.swift` | Entry point. Calls `setupInferenceEnvironment()` at launch. | |
| 48 | | `ContentView.swift` | The chat UI: header, empty state, message list, input bar, reload/clear actions. | |
| 49 | | `ChatViewModel.swift` | Bridges UniFFI streaming into Swift concurrency, manages model lifecycle, restores history, persists conversation. | |
| 50 | | `ExampleSupport.swift` | Prompt suggestions, sampling presets, and the settings sheet. | |
| 51 | | `InferenceEnvironment.swift` | Sets `HF_HOME` inside the app sandbox so HuggingFace downloads land somewhere iOS allows. | |
| 52 | | `project.yml` | XcodeGen spec. The `.xcodeproj` is generated from this, not checked in. | |