https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
j

Jozef Matus

11/08/2020, 1:46 PM
Hi guys, sorry for stupid question. I’ve seen multiple usages of
NSString.create(data = it, encoding = NSUTF8StringEncoding).toString()
and I cant find out how do you know about function name and definition. I have read on github kotlin native repo that those initializers are done via create factory but I cant find any documentation. Where can i find functions declarations please? I looked into platform.Foundation.NSString but I didn’t see
create
a

Alexey Glushkov

11/08/2020, 2:52 PM
Hi, it you can check the Apple doc to see all the available initializers. The one you mentioned is here: https://developer.apple.com/documentation/foundation/nsstring/1416374-initwithdata?language=objc The other ones are here: https://developer.apple.com/documentation/foundation/nsstring?language=objc
j

Jozef Matus

11/08/2020, 7:02 PM
Thank you for your time 🙂 I found apple’s documentation but in kotlin it is done via create factory. I’m interested to examine those kotlin functions declarations. Because it was not clear to my why should i use
create
I just copy pasted it from web. I would like to be able to go through available api and discover how to use it.
a

Alexey Glushkov

11/08/2020, 7:19 PM
but in kotlin it is done via create factory
Because it was not clear to my why should i use 
create
probably this factory wrapper is required for the right interop between kotlin and objc
I would like to be able to go through available api and discover how to use it
anyway as these factory functions are based on objc foundation you can easily infer available create methods looking at the apple doc Also, in my case when I type NSString.create, Android Studio autocompletion works as expected. Then I can jump to all the wrapped create methods using “go to type declaration” function. On my mac the file is placed here .konan/kotlin-native-prebuilt-macos-1.4.10/klib/commonized/ios_arm64-ios_x64-MS40LjEw/common/org.jetbrains.kotlin.native.platform.Foundation/default/linkdata/package_platform.Foundation/30_Foundation.knm
Copy code
// IntelliJ API Decompiler stub source generated from a class file
// Implementation of methods is not available

package platform.Foundation
...
public external expect fun <T : platform.Foundation.NSString> kotlinx.cinterop.ObjCClassOf<T>.create(cString: kotlinx.cinterop.CPointer<kotlinx.cinterop.ByteVar /* = kotlinx.cinterop.ByteVarOf<kotlin.Byte> */>?, length: platform.darwin.NSUInteger /* = kotlin.ULong */): T? { /* compiled code */ }

public external expect fun <T : platform.Foundation.NSString> kotlinx.cinterop.ObjCClassOf<T>.create(cStringNoCopy: kotlinx.cinterop.CPointer<kotlinx.cinterop.ByteVar /* = kotlinx.cinterop.ByteVarOf<kotlin.Byte> */>?, length: platform.darwin.NSUInteger /* = kotlin.ULong */, freeWhenDone: kotlin.Boolean): T? { /* compiled code */ }
...
I use
Copy code
Android Studio 4.1 RC 3
Build #AI-201.8743.12.41.6823847, built on September 10, 2020
j

Jozef Matus

11/08/2020, 7:21 PM
thanks for advice 🙂 In my android studio, it doesn’t work so maybe I have an issue in graddle.setup. Anyway, you helped me thanks!!
a

Alexey Glushkov

11/08/2020, 7:23 PM
great, just in case there’s my pet project where autocompletion works: https://github.com/soniccat/WordTeacher good luck with your investigation 🙂
14 Views