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

Ivy

01/10/2021, 4:03 PM
Hello, How do you manage String resources in Kotlin Multiplatform Mobile(Android & iOS)? I found this post(https://chrynan.codes/string-resources-in-kotlin-multiplatform/), but I wonder what the best practice is.
m

murdock

01/10/2021, 5:09 PM
This seems like a good way to go
e

edenman

01/10/2021, 6:05 PM
I do a hybrid of the “access by common identifier” pattern
i have a
StringRef
enum in my common library and then a
Resources
interface that has a
fun getString(ref: StringRef): CharSequence
method
then the android impl of the enum looks like
actual enum class StringRef(@StringRes val resID: Int)
so instead of a method that does the mapping, it’s baked into the definition of the enum
a

alex009

01/11/2021, 1:38 AM
i

Ivy

01/12/2021, 12:48 PM
@murdock @edenman @alex009 thank you. I applied a simple way at first. But I’m trying to understand the way of
moko-resources
.
a

alex009

01/12/2021, 1:28 PM
Strange to see that moko resources hard way) I will rethink readme
i

Ivy

01/12/2021, 2:55 PM
@alex009 Oh, it didn’t mean that
moko-resources
is hard to use. I cloned your team’s repository and then I saw how to generate the resource in moko-resource project such as MRGenerator. I mean that I am trying to understand moko-resource project structure.
977 Views