jean
12/25/2024, 10:22 PMval myCustomObject by remember { mutableStateOf(MyCustomObject()) }
If I try without mutableStateOf
I get the following compiler error Property delegate must have a 'getValue(Nothing?, KProperty0<*>)' method
.
I tried to add this to MyCustomObject
but it didn’t work
operator fun getValue(thisRef: Nothing?, property: KProperty0<*>): MyCustomObject = this
I get 'operator' modifier is not applicable to function: second parameter must be of type KProperty<*> or its supertype.
Is there a way to make this work? Or should I do it another way?Chrimaeon
12/25/2024, 10:51 PMby
keyword means and why you cannot use it without the mutableState
https://kotlinlang.org/docs/delegated-properties.html
The you will realize that you can just use remember
and a simple assignment.Sargun Vohra
12/26/2024, 3:05 AMgetValue
as an extension function. You just need to import it. If you’re using Android Studio or Fleet, that import should be suggested for youSargun Vohra
12/26/2024, 3:06 AM=
instead of by
jean
12/26/2024, 10:24 AMMyCustomObject
with by
to the MyCustomObject
class itself. From what read in the doc, that’s not how it’s meant to be used. val myObject = remember { MyCustomObject() }
works fine, thanks for the help!