Igal Avraham
06/24/2022, 1:21 AMIgal Avraham
06/24/2022, 6:04 AMokarm
06/26/2022, 4:02 PMinternal actual fun encode(text: String, charset: Charset): ByteArray {
var cfCharsetName: CPointer<__CFString>? = null
try {
// (1) Cast a NSString as CFStringRef for the CF lookup function.
// The BridgingRetain function will transfer the ownership to us,
// making us responsible for freeing the memory.
cfCharsetName = CFBridgingRetain(charset.ianaName as NSString) as CFStringRef?
// (2) Using the prepared CFStringRef, find the CFStringEncoding.
val cfEncoding = CFStringConvertIANACharSetNameToEncoding(cfCharsetName)
if (cfEncoding == kCFStringEncodingInvalidId) {
throw RuntimeException("invalid encoding: ${charset.ianaName}")
}
// (3) Using the CF encoding, find the corresponding NSStringEncoding
val nsEncoding = CFStringConvertEncodingToNSStringEncoding(cfEncoding)
// (4) Encode the Kotlin String using the NS Encoding. The resulting NSData
// lives in the ARC-enabled iOS runtime and since it does not escape the current
// scope, will be collected when scope ends.
val encodedData: NSData =
(text as NSString).dataUsingEncoding(nsEncoding, allowLossyConversion = true)
?: throw RuntimeException("encoder failed")
val encodedBytes = encodedData.bytes ?: throw RuntimeException("encoder failed")
// (5) Create a Kotlin-land ByteArray and copy over the encoded bytes
// from the ObjC-land NSData.
//
// <https://github.com/JetBrains/kotlin-native/issues/3172>
return ByteArray(encodedData.length.toInt()).apply {
usePinned { pinnedByteArray ->
memcpy(pinnedByteArray.addressOf(0), encodedBytes, encodedData.length)
}
}
} finally {
// Don't forget to free the unmanaged CF pointer!
CFRelease(cfCharsetName)
}
}
Vsevolod Ganin
06/27/2022, 1:09 PMtry ... catch ...
in Kotlin while calling interface
method implemented in swift/objc? I saw relatively new ForeignException
but afaik it only works for cinteroped libraries with special flagMatt Nelson
06/27/2022, 2:43 PMsealed interface
will compile to objective-c? Is it the same as how it compiles as just an interface
for Java?
Wondering if it would have been better for kotlin.Result
to have been a sealed interface
with an underlying private value class
such that it could compile to other platforms...Muhammet Emin Gündoğar
06/28/2022, 4:33 PMJames Good
06/30/2022, 6:29 AMspierce7
06/30/2022, 3:16 PMLandry Norris
06/30/2022, 4:38 PMAditya Kurkure
07/01/2022, 8:11 AMJsonEncoder
and JsonDecoder
in Kotlin native? I noticed a JsonDecoder in Mapkit but can't see the Encoder in the same package.spierce7
07/04/2022, 5:42 PMStrings <exe> | grep -i <name of module>
hfhbd
07/05/2022, 12:11 PMhfhbd
07/05/2022, 4:51 PMJeff Lockhart
07/06/2022, 12:56 AMexternal expect fun
definitions to a pre-defined ObjC interop? I'm using an ObjC cocoapods library and need to call a function that's not part of its public API for testing. I know the function signature from its source code. Basically, I just need a way to ObjC "message" the function in Kotlin. Or something akin to Java reflection to access it.kevin.cianfarini
07/06/2022, 2:01 PMNSNumber
to kotlin.Number
? Is it just myNsNumber as Number
?Dmitry Motyl
07/06/2022, 3:38 PMClass SharedXXX is implemented in both YYY and ZZZ. One of the two will be used. Which one is undefined.
Has anybody solved this problem ?ankushg
07/07/2022, 7:02 PMVARIABLE_IN_SINGLETON_WITHOUT_THREAD_LOCAL
?Jeff Lockhart
07/09/2022, 9:44 PMribesg
07/10/2022, 12:40 PMnatario1
07/10/2022, 7:02 PM.konan/dependencies/apple-llvm-20200714-macos-aarch64-essentials
? I’m thinking I might override the relevant property in konan.properties
, but I’m not sure if it’s the right approach. Is anyone doing this?Pavel Gorgulov
07/11/2022, 10:43 AM16:22:47 Exception in thread "main" org.jetbrains.kotlin.konan.KonanExternalToolFailure: The /mnt/agent/system/.persistent_cache/konan/dependencies/llvm-11.1.0-linux-x64-essentials/bin/clang++ command returned non-zero exit code: 1.
16:22:47 output:
16:22:47 /mnt/agent/work/40296c97b9f61601/multik-native/multik_jni/src/main/cpp/mk_linalg.cpp:22:27: error: use of undeclared identifier 'creal'
16:22:47 return mk_complex_float{openblas_complex_float_real(ret), openblas_complex_float_imag(ret)};
16:22:47 ^
16:22:47 /mnt/agent/work/40296c97b9f61601/multik-native/build/cmake-build/openblas-install/include/openblas_config.h:128:55: note: expanded from macro 'openblas_complex_float_real'
16:22:47 #define openblas_complex_float_real(z) (creal(z))
hfhbd
07/11/2022, 2:46 PMvar GetStringUTFChars: kotlinx.cinterop.CPointer<kotlinx.cinterop.CFunction<
in JNINativeInterface
. But getting this "function" fails and I don't know why. I don't invoke the function yet.Jeff Lockhart
07/12/2022, 4:20 PMJeff Lockhart
07/12/2022, 4:53 PMtypealias InterfaceName = (param: ParamType) -> ReturnType
?Pardip
07/13/2022, 1:46 PMabstract class A {
init {
foo()
}
abstract fun foo()
}
class B : A {
val b = /* init b */
override fun foo() {
b.something() // crash
}
}
The super class call foo()
on init so, the property b
is not yet initialisedBig Chungus
07/14/2022, 11:54 AMBrian Guertin
07/14/2022, 8:31 PM* Source files:
* Compiler version info: Konan: 1.7.0 / Kotlin: 1.7.20
* Output kind: FRAMEWORK
AmrJyniat
07/15/2022, 8:29 AMabstract class A {
abstract foo(param1: Any): Any
abstract foo(param1: Any, param2, Any): Any
}
class B: A {
//ask me to override one fun at lease and make the other fun optional
override foo(param1: Any): Any {
......
}
}
I'll always inject the foo()
fun with all parameters, but I don't need them in the inherited class in most casesAnton Afanasev
07/15/2022, 3:34 PMvar onStateChanged: ((from: State, to: State) -> Unit)?
translated to:
@property void (^ _Nullable onStateChanged)(State *, State *) __attribute__((swift_name("onStateChanged")));
which makes this function signature problematic to read on iOS.
Are there any way to pass/enforce argument name on k\n?
PS. I mean that argument names from
and to
are ignored during kotlin to swift translation.Trey
07/20/2022, 9:36 PMTrey
07/20/2022, 9:36 PM