question, is is possible to retrieve data already ...
# kotlin-native
t
question, is is possible to retrieve data already stored in NSData using pure kotlin common and a library? I'm not an IOS-developer, but I want to convince to switch...
j
See my post here. I found a gist for converting to and from
NSData
to
ByteArray
. I also figured out how to do the same thing with
CFDataRef
.
s
It can’t be done in common code since common doesn’t know anything about individual platforms. You have two options for plugging this capability into your common code. If the common code is going to instantiate the class reading the NSData, I would suggest using the
expect/actual
features of KMP. If the data reading class will be given to the calling code as a dependency, a simple interface will work fine. One nice thing about the interface approach is that it doesn’t matter if the interface is implemented in Kotlin, Swift or ObjC. Sometimes it is easier to work with the Cocoa apis using Swift rather than Kotlin.