-
Notifications
You must be signed in to change notification settings - Fork 89
Home
John O'Reilly edited this page Oct 21, 2022
·
3 revisions
The shared code is published as a Swift Package (using the KMMBridge tool). To use just go to File/Add Package in XCode and enter https://github.com/joreilly/Confetti (as shown below)
![Screenshot 2022-10-21 at 16 27 05](https://user-images.githubusercontent.com/6302/197241387-025995b4-74a3-45e6-b097-241493494e19.png)
Note that this uses https://github.com/rickclephas/KMP-NativeCoroutines library and right now Swift Package for this needs to be also manually added in XCode.
import SwiftUI
import ConfettiKit
import KMPNativeCoroutinesAsync
struct ContentView: View {
let repository = ConfettiRepository()
@State var sessions: [SessionDetails] = []
var body: some View {
List(sessions, id: \.id) { session in
VStack(alignment: .leading) {
Text(session.title).bold()
Text(session.room?.name ?? "")
}
}
.task {
await observeSessions()
}
}
func observeSessions() async {
repository.setConference(conference: "droidconlondon2022")
do {
let stream = asyncStream(for: repository.sessionsNative)
for try await data in stream {
self.sessions = data
}
} catch {
print("Failed with error: \(error)")
}
}
}
Note that it's also necessary to initialise Koin (like following for example)
import SwiftUI
import ConfettiKit
@main
struct YourApp: App {
init() {
KoinKt.doInitKoin()
}
var body: some Scene {
WindowGroup {
ContentView()
}
}
}