Installation
Swift Package Manager
Add the package dependency in Xcode:
- File → Add Package Dependencies
- Enter:
https://github.com/decartai/decart-ios
- Select version and add to your target
Or add to your Package.swift
:
dependencies: [
.package(url: "https://github.com/decartai/decart-ios.git", from: "0.0.1")
]
Quick Start
import DecartSDK
import WebRTC
// Create client
let config = try DecartConfiguration(
apiKey: "your-api-key-here"
)
let client = try createDecartClient(configuration: config)
// Select model
let model = Models.realtime(.lucy_v2v_720p_rt)
// Capture camera stream
let stream = try await captureLocalStream(
fps: model.fps,
width: model.width,
height: model.height
)
// Connect and transform
let realtimeClient = try await client.realtime.connect(
stream: stream,
options: RealtimeConnectOptions(
model: model,
onRemoteStream: { transformedStream in
// Display the transformed video
videoView.srcObject = transformedStream
},
initialState: ModelState(
prompt: Prompt(text: "Anime style", enrich: true)
)
)
)
// Change style on the fly
try await realtimeClient.setPrompt("Cyberpunk city")
// Disconnect when done
await realtimeClient.disconnect()
What can you build?
The Swift SDK currently provides the Realtime API for building interactive iOS and macOS applications:
Realtime API
Transform video streams in realtime with WebRTC on iOS and macOS
The Swift SDK requires:
- iOS 15.0+ or macOS 12.0+
- Swift 5.9+
- Xcode 15.0+
- A real device for camera access (simulator not supported for camera features)
Client Setup
Initialize the Decart client with your API key:
import DecartSDK
let config = try DecartConfiguration(
apiKey: "your-api-key-here",
baseURL: "https://api3.decart.ai" // optional
)
let client = try createDecartClient(configuration: config)
Parameters:
apiKey
(required) - Your Decart API key from the platform
baseURL
(optional) - Custom API endpoint (defaults to Decart’s production API)
Store your API key securely. Never commit API keys to version control. Use environment variables or secure storage like Keychain.
Available Models
Import models from the SDK to use with the Realtime API:
import DecartSDK
// Realtime models
Models.realtime(.mirage) // Realtime video transformation
Models.realtime(.lucy_v2v_720p_rt) // Realtime video editing
Each model has specific properties for optimal performance:
let model = Models.realtime(.lucy_v2v_720p_rt)
print(model.fps) // 25
print(model.width) // 1280
print(model.height) // 704
Swift Concurrency
The SDK is built with modern Swift concurrency using async/await and actors:
// All SDK methods are async
let client = try await client.realtime.connect(...)
// RealtimeClient is an actor for thread-safe access
public actor RealtimeClient {
public func setPrompt(_ prompt: String) async throws
public func disconnect() async
}
Use async/await
throughout your application for best integration with the SDK. The actor-based design ensures thread-safety when accessing the realtime client from multiple contexts.
Combine Integration
The SDK provides Combine publishers for reactive state management:
import Combine
var cancellables = Set<AnyCancellable>()
// Subscribe to connection state changes
realtimeClient.connectionStatePublisher
.sink { state in
print("Connection: \(state)")
}
.store(in: &cancellables)
// Subscribe to errors
realtimeClient.errorPublisher
.sink { error in
print("Error: \(error.localizedDescription)")
}
.store(in: &cancellables)
SwiftUI Integration
The SDK works seamlessly with SwiftUI:
import SwiftUI
import DecartSDK
struct VideoView: UIViewRepresentable {
let videoView: RTCMTLVideoView
func makeUIView(context: Context) -> RTCMTLVideoView {
videoView.contentMode = .scaleAspectFill
return videoView
}
func updateUIView(_ uiView: RTCMTLVideoView, context: Context) {}
}
struct ContentView: View {
@StateObject private var viewModel = RealtimeViewModel()
var body: some View {
VideoView(videoView: viewModel.remoteVideoView)
.onAppear {
Task { await viewModel.connect() }
}
}
}
Privacy Permissions
Your app must request camera and microphone permissions. Add these keys to your Info.plist
:
<key>NSCameraUsageDescription</key>
<string>This app needs camera access for video transformation</string>
<key>NSMicrophoneUsageDescription</key>
<string>This app needs microphone access for audio in video</string>
Type Safety
The SDK is fully type-safe with compile-time guarantees:
// Models enforce correct configuration
let model = Models.realtime(.mirage)
// RealtimeClient methods are type-checked
try await realtimeClient.setPrompt("Anime") // ✅ String
try await realtimeClient.setMirror(true) // ✅ Bool
// Errors are strongly typed
catch let error as DecartError {
switch error {
case .invalidAPIKey:
print("Invalid API key")
case .webRTCError(let underlyingError):
print("WebRTC error: \(underlyingError)")
default:
print(error.localizedDescription)
}
}
Error Handling
All errors conform to Swift’s LocalizedError
protocol:
do {
let client = try await client.realtime.connect(...)
} catch let error as DecartError {
print("Error code: \(error.errorCode)")
print("Description: \(error.localizedDescription)")
}
Example App
The SDK includes a complete example iOS app that demonstrates all features:
- Camera capture and video rendering
- Real-time video transformation
- Interactive prompt updates
- Mirror mode toggle
- Connection state management
- Error handling
Clone the repository to try it on your device:
git clone https://github.com/DecartAI/decart-ios.git
cd decart-ios/Examples/RealtimeExample
open RealtimeExample.xcodeproj
Ready to start building?