Is there a way to import SPM native iOS packages i...
# multiplatform
z
Is there a way to import SPM native iOS packages in common code?
f
no, not possible, as it’s not possible to generate a framework directly from a package
z
What would be the best approach then? assumming i have control over the iOS SDK, if i publish it in cocopods, would it make it possible?
f
yes, cocoapods is the easy way to import iOS dependency into the command code.
Another way, but quite limited, https://github.com/ttypic/swift-klib-plugin
z
I was just reading this as you have posted this in another response! thank you for your help!! 🙏
j
Probably not answer you're looking for but we've found it pretty straightforward to implement say some Kotlin inteface in Swift (in iOS app) and pass that implementation (which uses the Swift Package) to shared code (particularly useful when creating CMP apps)
z
Not sure i understand what you mean, are you suggesting i use kotlin code to control the iOS SDK in the iosApp? than expose some states for the CMP? It sounds reasonable but i am not sure how to approach this, i need to interact with some structs that the SDK exposes, and also to initilize its instance some how...
j
yeah, in a CMP app in particular as mentioned the shared code is typically where initialisation is triggered from so makes sense in that case I think....we're using it to initialise a number of 3rd party services that only expose APIs through Swift Packages (on the iOS side).....and then initialising (using Android SDK) in androidMain etc
z
Do you have any open-source examples i can reference that initialises swift packages from the CMP module?
j
Mostly doing this in work project.....don't think samples I have are doing that right now....
actually, a little bit different but have example of using somewhat similar approach for including SwiftUI view in shared Compose code here https://johnoreilly.dev/posts/exploring-compose_multiplatform_sharing_ios/
z
Amazing! thank you for your help!
j
🔥 1
that has
GenerativeModel
interface in shared code that's implemented in Swift in IOS app (uses Firebase Vertex Ai SDK)
z
Copy code
ComposeApp.GenerativeModel
Is imported in the iosApp? looks promising
I will dive into this, thank you!!