colinta
colinta

Reputation: 3659

How can I pass an objective-C object into a Kotlin Native framework?

In particular, I need to zip a directory of files, and turn that into a single file.

// put all the log files in zipDirectory into a zip file named toFile
actual fun zip(zipDirectory: String, toFile: String)

I wasn't worried about this feature, because I had glibly assumed I could pass in an objective-c object into this object's constructor, and use it to run some cocoapods code... how wrong I was!

So now I'm trying to figure out the best way to accomplish this task. Would love some ideas!

Upvotes: 0

Views: 956

Answers (1)

Phil Dukhov
Phil Dukhov

Reputation: 87894

You have two options:

  1. Using cocoapods plugin and importing cocoapod to your KMM module, so you can use it in your actual fun of iosMain, without needing to pass anything to the constructor. Check out about it here.
  • pros: much less code
  • cons: each pod added to KMM increases build time significantly, and as long as the cocoapods build caching is broken (KT-43796) I find it unusable.
  1. Create an interface/abstract class for a "zipper", create constructor that take it, implement an instance of it on the iOS side and pass to the constructor.

Upvotes: 2

Related Questions