# random

Michael Bichlmeier

10/15/2023, 11:38 AM
Is there a way (or better what is the best way) to do get rid of the
in each icon element?
Copy code
object Icons {
    private const val PREFIX = "drawable/"
    const val LOGO = PREFIX + "icon.xml"
    const val AGAIN = PREFIX + "again.xml"
Is there a better way and how can I reduce the prefix redundancy? I want to call
which represents
and this with many other types.

Youssef Shoaib [MOD]

10/15/2023, 2:24 PM
Copy code
interface Prefixing {
  val prefix: String
  operator fun String.getValue(thisRef: Prefixing, property: KProperty<*>) = prefix + this

object Icons: Prefixing {
  override val prefix = "drawable/"
  val LOGO by "icon.xml"
  val AGAIN by "again.xml"
🙌 2
Dealing with raw strings feels a little precarious though, so maybe you want to have some value class XmlFile that must be constructed with a prefix and a filename, and which is simply represented by a single string. Then, you can define new methods that replace the Android ones but only operate on the XmlFile typed values

Loney Chou

10/15/2023, 3:32 PM
Maybe wait for const functions?