icerockdev / moko-mvvm

Model-View-ViewModel architecture components for mobile (android & ios) Kotlin Multiplatform development
https://moko.icerock.dev/
Apache License 2.0
1k stars 95 forks source link

Moko Swift extensions are failed to compile #28

Closed caesar84mx closed 4 years ago

caesar84mx commented 4 years ago

The Swift extensions for Moko LiveData are failed to compile with "Use of undeclared type LiveData" message. It happens because after compiling the shared library the respective class names have "Mvvm" prefix. Moreover, when I change the names to the correct ones, happens that they don't have generics which leads to new compilation errors.

Screen Shot 2020-02-28 at 17 33 50
Alex009 commented 4 years ago

hello! in your case prefix Mvvm added because you not add moko-mvvm into export libraries for framework. in sample it done with mobile-multiplatform-gradle-plugin - https://github.com/icerockdev/moko-mvvm/blob/22b50b8919c565d2de24738c9183c93cc475fdc7/sample/mpp-library/build.gradle.kts#L22

if you not use this plugin you should use this guide - https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#exporting-dependencies-in-frameworks

when you export dependencies into framework header prefix Mvvm not added

caesar84mx commented 4 years ago

Thanks for your response. I did as you said and now I'm having the following in my module's build.gradle:

targets {
        android()

        iosArm64("iosArm64")
        iosX64("iosX64")

        configure([iosArm64, iosX64]) {
            binaries {
                framework {
                    baseName = "MultiPlatformLibrary"
                    transitiveExport = true
                }
            }
        }
    }

And:

   iosX64 {
        binaries {
            framework("MultiPlatformLibrary") {
                export "dev.icerock.moko:mvvm-iosx64:$moko_mvvm_version"
            }
        }
    }

    iosArm64 {
        binaries {
            framework("MultiPlatformLibrary") {
                export "dev.icerock.moko:mvvm-iosarm64:$moko_mvvm_version"
            }
        }
    }

Now the library is being compiled without class names alteration. But when I try to build an iOS project in Xcode, I have the following:

Screen Shot 2020-03-02 at 15 05 11
Alex009 commented 4 years ago

enable generics support please https://kotlinlang.org/docs/reference/native/objc_interop.html#generics

caesar84mx commented 4 years ago

A huge thanks to you, it finally worked 👍