Skip to content
John O'Reilly edited this page Oct 21, 2022 · 3 revisions

Welcome to the Confetti wiki!

Using Swift Package

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

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.

Example SwiftUI code

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()
        }
    }
}
Clone this wiki locally