Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unresolved reference: Transformations

I'm trying to follow the android documentation to implement Transformations in my project but I run into this problem Unresolved reference: Transformations. I don't know why my project can't see the Transformations class.

I'm using Kotlin version 1.5.21' and here is my code

class MyViewModel(private val repository: PostalCodeRepository) : ViewModel() {
    private val addressInput = MutableLiveData<String>()
    val postalCode: LiveData<String> = Transformations.switchMap(addressInput) {
            address -> repository.getPostCode(address) }


    private fun setInput(address: String) {
        addressInput.value = address
    }
}

Any guidance is really appreciated.

like image 321
user3765730 Avatar asked Sep 01 '25 22:09

user3765730


1 Answers

From lifecycle version 2.6.0 instead of using Transformations, you need to use the extension function directly myLiveData.switchMap or myLiveData.map (source)

like image 131
soft2enjoy Avatar answered Sep 03 '25 14:09

soft2enjoy