ZeticMLangeModel
Complete API reference for the ZeticMLangeModel class on iOS.
The ZeticMLangeModel class is the primary interface for running on-device AI inference on iOS. It handles model downloading, Neural Engine context initialization, and hardware-accelerated execution through a single unified Swift API.
Import
import ZeticMLangeInitializer
ZeticMLangeModel(personalKey:name:)
Creates a new model instance, downloading the optimized binary if needed and initializing the NPU execution context.
init(personalKey: String, name: String) throws| Parameter | Type | Description |
|---|---|---|
personalKey | String | Your personal authentication key from the Melange Dashboard. |
name | String | The unique identifier for your compiled model (e.g., "Steve/YOLOv11_comparison"). |
Throws: An error if the model cannot be downloaded or the Neural Engine context fails to initialize.
let model = try ZeticMLangeModel(personalKey: "YOUR_PERSONAL_KEY", name: "YOUR_MODEL_KEY")The initializer performs a network call on first use to download the model binary. The binary is cached locally after the first download, so subsequent initializations are fast.
ZeticMLangeModel(personalKey:name:version:)
Creates a new model instance targeting a specific model version.
init(personalKey: String, name: String, version: Int) throws| Parameter | Type | Description |
|---|---|---|
personalKey | String | Your personal authentication key. |
name | String | The unique identifier for your compiled model. |
version | Int | The specific version of the model to load. |
let model = try ZeticMLangeModel(personalKey: PERSONAL_KEY, name: MODEL_NAME, version: VERSION)ZeticMLangeModel(personalKey:name:modelMode:)
Creates a new model instance with a specific inference mode.
init(personalKey: String, name: String, modelMode: ModelMode) throws| Parameter | Type | Description |
|---|---|---|
personalKey | String | Your personal authentication key. |
name | String | The unique identifier for your compiled model. |
modelMode | ModelMode | Inference strategy: RUN_AUTO, RUN_SPEED, or RUN_ACCURACY. See Enums. |
let model = try ZeticMLangeModel(personalKey: PERSONAL_KEY, name: MODEL_NAME, modelMode: RUN_SPEED)Methods
run(_:)
Executes inference on the loaded model using the provided input tensors.
func run(_ inputs: [Tensor]) throws -> [Tensor]| Parameter | Type | Description |
|---|---|---|
inputs | [Tensor] | An array of input tensors matching the model's expected input shapes and data types. |
Returns: [Tensor]: The model's output tensors.
Throws: An error if input shapes do not match the model's expected inputs, or if inference execution fails.
let outputs = try model.run(inputs)Full Working Example
import ZeticMLange
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
do {
// (1) Load model
// Downloads the optimized binary on first run, then caches locally
let model = try ZeticMLangeModel(personalKey: PERSONAL_KEY, name: "Steve/YOLOv11_comparison")
// (2) Prepare model inputs
// Ensure input shapes match your model's requirement (e.g., Float32 arrays)
let inputs: [Tensor] = [] // Prepare your inputs
// (3) Run Inference
// Executes the fully automated hardware graph.
// No manual delegate configuration or memory syncing required.
let outputs = try model.run(inputs)
// (4) Process outputs
// outputs is a [Tensor] containing the model's results
for output in outputs {
// Process each output tensor
}
} catch {
print("Melange error: \(error)")
}
}
}Always ensure your input tensor shapes exactly match what the model expects. A shape mismatch will throw an error. Check the model's input specification on the Melange Dashboard.
Swift Package Manager Setup
Add the Melange package to your Xcode project:
- Open your project in Xcode
- Go to File then Add Package Dependencies
- Enter the repository URL:
https://github.com/zetic-ai/ZeticMLangeiOS - Click Add Package
- Select
ZeticMLangeand link it to your app target
See Also
- iOS Integration Guide: Step-by-step setup guide
- ZeticMLangeModel (Android): Android equivalent
- Common Errors: Troubleshooting guide