I am developing a library and am having some strug...
# touchlab-tools
m
I am developing a library and am having some struggle with the
Swift Code Bundling
I am putting my swift files to the iosMain/swift folder it seems they are not able to see my Kotlin classes. In my commonMain I have a class called MessageView
Copy code
open class MessageView(
    val message: Message,
    protected val eventActionFactory: ActionFactoryApi<ActionModel>
) {

    open fun onDelete() {
        // delete message
    }
}
And an object called Sdk
Copy code
object Sdk {
   val inbox: InboxApi
        get() = DependencyInjection.container.inboxApi
}
It is pretty simple I would say I would like to have a SwiftUI based view for my MessageView so I though bundling a Swift implementation to my framework is exactly what I need so I've created these two Swift files under iosMain/swift SwiftMessageView.swift
Copy code
import Foundation
import SwiftUI


public class SwiftMessageView: MessageView {
    public func show(body: (message) -> some View = { VStack { Text(message.title) } }) {
        VStack {
            body(self.message)
        }
    }
}
SwiftSdk.swift
Copy code
import Foundation
import SwiftUI


public class SwiftSdk {
    public static func inbox() async -> [SwiftMessageView] {
        do {
            let messagesResult = try await Sdk.inbox.fetchMessages()
            switch messagesResult {
            case .success(let messages):
            return messages.map { message in
                let eventActionFactory = DependencyInjection.getDependencyContainerPrivateApi()
                .pushActionFactory
                let messageView = SwiftMessageView(
                message: message, eventActionFactory: eventActionFactory)
                return messageView
            }
            case .failure(let error):
            print("Error fetching messages: \(error)")
            return []
            }
        } catch {
            print("Error fetching messages: \(error)")
            return []
        }
    }
}
But neither the Sdk or the SwiftMessageView are available in the SwiftSdk.swift. The plugin is applied I have only one gradle module. Any ideas what I am doing wrong? it fails while linking the framework
Copy code
./gradlew :sdk:linkReleaseFrameworkIosX64 :sdk:linkReleaseFrameworkIosArm64 :sdk:linkReleaseFrameworkIosSimulatorArm64
Can someone point me to the right direction please?
It turned out most of my problems were caused by the missing autocomplete&proper syntax highlight. It works perfectly. Any tips to workaround this limitation for people not too familiar with swift? 🙂
m
You mean you are missing autocomplete of common code in xcode ?
m
I am missing the autocomplete for the swift files under the swift folder. It makes it hard to ensure they are syntactically correct.
m
just had a thread on this, its a QOL improvement they want to do but there isnt a super simple solution right now. https://kotlinlang.slack.com/archives/CTJB58X7X/p1729519745781849
If the flow Tadeas mentions doesnt work for you the approach my team is going with for right now is basically having a
Sources
folder at the top level of the KMP repo and our Package.swift exports that swift code as a second target that depends on the kmp lib. Then we can just open the repo in xcode and get auto complete. Big downside of this is were pushing up two libraries, basically KmpLib and KmpLib_Swift where the swift one is all the wrapper code. It works for us since we're wrapping all of the kotlin code in the swift so the expecte ios dev flow is to never import KmpLib and only use KmpLibSwift
You could also blend our two flows and write the swift code using my flow for the autocomplete, then just copy it into
iosMain/swift
to bundle it with the kmp lib
t
Seems like we might want to prioritize the temporary Xcode project generator feature for SKIE
👌 2
m
The secret to getting open source tasks prioritized is to make two accounts and ask about the same thing twice in a day think smart
😅 4
t
Well, prioritization is one thing, getting time to do it is where we're now short 😄