megax
10/24/2024, 8:29 AMSwift 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
open class MessageView(
val message: Message,
protected val eventActionFactory: ActionFactoryApi<ActionModel>
) {
open fun onDelete() {
// delete message
}
}
And an object called Sdk
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
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
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
./gradlew :sdk:linkReleaseFrameworkIosX64 :sdk:linkReleaseFrameworkIosArm64 :sdk:linkReleaseFrameworkIosSimulatorArm64
Can someone point me to the right direction please?megax
10/24/2024, 12:34 PMMuaz KADAN
10/25/2024, 6:17 AMmegax
10/25/2024, 7:13 AMMichael Friend
10/25/2024, 2:08 PMMichael Friend
10/25/2024, 2:12 PMSources
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 KmpLibSwiftMichael Friend
10/25/2024, 2:13 PMiosMain/swift
to bundle it with the kmp libTadeas Kriz
10/25/2024, 2:29 PMMichael Friend
10/25/2024, 2:31 PMTadeas Kriz
10/25/2024, 2:32 PM