https://kotlinlang.org logo
Title
p

phldavies

06/08/2020, 8:46 AM
What’s the correct/safe way to get a
CFStringRef
(like the
kCFBundleNameKey
constant) as a Kotlin
String
?
p

phldavies

06/08/2020, 9:33 AM
Thanks, @Nikolay Kasyanov , I found that before and have tried using
CFBridgingRelease
however I found it crashes occasionally - I assume because it’s changing the ownership of the constant pointer? I assume it would be safer to create a copy of the string each time (or cache it) ?
n

Nikolay Kasyanov

06/08/2020, 9:33 AM
I’m just using a string literal instead of a constant, works like a charm
https://youtrack.jetbrains.com/issue/KT-38528#focus=streamItem-27-4109183.0-0 there’s also an option to add a
CFBridgingRetain
call to balance for the release
p

phldavies

06/08/2020, 9:35 AM
I think a set of constant string literals in the kotlin code would probably be safer. I doubt they’ll change the values any time soon 😉
n

Nikolay Kasyanov

06/08/2020, 9:43 AM
exactly