-
Notifications
You must be signed in to change notification settings - Fork 96
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)
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()
}
}
}