0
# Compose Runtime for iOS UIKit x64
1
2
Compose Runtime for iOS UIKit x64 provides the core runtime library for Compose Multiplatform targeting iOS UIKit x64 architecture (iOS simulator on Intel Macs). This runtime enables declarative UI development by providing state management, composition lifecycle, and platform integration capabilities for iOS applications.
3
4
## Package Information
5
6
- **Package Name**: org.jetbrains.compose.runtime:runtime-uikitx64
7
- **Package Type**: maven
8
- **Language**: Kotlin
9
- **Installation**: Add to your `build.gradle.kts`:
10
11
```kotlin
12
dependencies {
13
implementation("org.jetbrains.compose.runtime:runtime-uikitx64:1.8.2")
14
}
15
```
16
17
## Core Imports
18
19
```kotlin
20
import androidx.compose.runtime.*
21
import androidx.compose.runtime.snapshots.*
22
```
23
24
## Basic Usage
25
26
```kotlin
27
import androidx.compose.runtime.*
28
29
@Composable
30
fun CounterApp() {
31
var count by remember { mutableStateOf(0) }
32
33
Column {
34
Text("Count: $count")
35
Button(onClick = { count++ }) {
36
Text("Increment")
37
}
38
}
39
}
40
41
// iOS Integration
42
fun MainViewController(): UIViewController = ComposeUIViewController {
43
CounterApp()
44
}
45
```
46
47
## Architecture
48
49
Compose Runtime is built around several key components:
50
51
- **State Management**: Reactive state system with automatic recomposition triggering
52
- **Composition Tree**: Hierarchical structure representing the UI composition
53
- **Snapshot System**: Efficient state tracking and change detection mechanism
54
- **Effect System**: Lifecycle-aware side effects and resource management
55
- **Platform Integration**: iOS UIKit specific threading and memory management
56
57
## Capabilities
58
59
### State Management
60
61
Core state management functionality providing reactive state holders and change detection. Essential for building dynamic UIs that respond to data changes.
62
63
```kotlin { .api }
64
fun <T> mutableStateOf(value: T): MutableState<T>
65
fun <T> derivedStateOf(calculation: () -> T): State<T>
66
67
interface State<out T> {
68
val value: T
69
}
70
71
interface MutableState<T> : State<T> {
72
override var value: T
73
}
74
```
75
76
[State Management](./state-management.md)
77
78
### Composition and Lifecycle
79
80
Composition management and lifecycle control for building and managing UI component trees. Handles component creation, updates, and disposal.
81
82
```kotlin { .api }
83
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.TYPE)
84
annotation class Composable
85
86
fun <T> remember(calculation: () -> T): T
87
fun <T> remember(key1: Any?, calculation: () -> T): T
88
```
89
90
[Composition Lifecycle](./composition-lifecycle.md)
91
92
### Effect System
93
94
Side effect management with lifecycle-aware execution and automatic cleanup. Provides safe ways to perform operations outside the composition scope.
95
96
```kotlin { .api }
97
fun DisposableEffect(
98
key1: Any?,
99
effect: DisposableEffectScope.() -> DisposableEffectResult
100
): Unit
101
102
fun LaunchedEffect(
103
key1: Any?,
104
block: suspend CoroutineScope.() -> Unit
105
): Unit
106
107
fun SideEffect(effect: () -> Unit): Unit
108
```
109
110
[Effects](./effects.md)
111
112
### CompositionLocal
113
114
Context-like data flow mechanism for passing data implicitly down the composition tree without explicit parameter passing.
115
116
```kotlin { .api }
117
abstract class CompositionLocal<T>(defaultFactory: (() -> T)?)
118
abstract class ProvidableCompositionLocal<T> : CompositionLocal<T>
119
120
fun <T> compositionLocalOf(defaultFactory: (() -> T)? = null): ProvidableCompositionLocal<T>
121
fun <T> staticCompositionLocalOf(defaultFactory: (() -> T)? = null): ProvidableCompositionLocal<T>
122
123
@Composable
124
fun CompositionLocalProvider(
125
vararg values: ProvidedValue<*>,
126
content: @Composable () -> Unit
127
): Unit
128
```
129
130
[CompositionLocal](./composition-local.md)
131
132
### Snapshot System
133
134
Low-level snapshot-based state management providing efficient change tracking and transactional state updates.
135
136
```kotlin { .api }
137
abstract class Snapshot {
138
companion object {
139
val global: MutableSnapshot
140
val current: Snapshot
141
142
fun takeSnapshot(readObserver: ((Any) -> Unit)? = null): Snapshot
143
fun takeMutableSnapshot(
144
readObserver: ((Any) -> Unit)? = null,
145
writeObserver: ((Any) -> Unit)? = null
146
): MutableSnapshot
147
}
148
}
149
150
fun <T> snapshotFlow(block: () -> T): Flow<T>
151
```
152
153
[Snapshot System](./snapshot-system.md)
154
155
### iOS Integration
156
157
Platform-specific integration for embedding Compose Multiplatform in iOS UIKit applications with seamless interoperability.
158
159
```kotlin { .api }
160
fun ComposeUIViewController(
161
content: @Composable () -> Unit
162
): UIViewController
163
164
fun ComposeUIViewController(
165
configure: UIViewController.() -> Unit = {},
166
content: @Composable () -> Unit
167
): UIViewController
168
169
@Composable
170
fun UIKitView(
171
factory: () -> UIView,
172
modifier: Modifier = Modifier,
173
update: (UIView) -> Unit = {}
174
)
175
```
176
177
[iOS Integration](./ios-integration.md)
178
179
## Error Handling
180
181
The runtime can throw the following exceptions:
182
183
- **IllegalStateException**: When composable functions are called outside of composition context
184
- **IllegalArgumentException**: When invalid parameters are passed to runtime functions
185
- **ConcurrentModificationException**: When snapshot conflicts occur during state updates
186
187
## Platform-Specific Features
188
189
### iOS UIKit Integration
190
191
- **Threading**: Integrates with iOS main thread and run loop
192
- **Memory Management**: Works with iOS ARC and autorelease pools
193
- **View Hosting**: `ComposeUIViewController` for embedding Compose in UIKit
194
195
### Performance Considerations
196
197
- State changes trigger minimal recomposition through precise invalidation
198
- Snapshot system provides efficient state tracking with structural sharing
199
- iOS-specific optimizations for UIKit integration and x64 architecture
200
- Automatic memory management with proper UIKit lifecycle integration