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.
From lifecycle version 2.6.0 instead of using Transformations, you need to use the extension function directly myLiveData.switchMap or myLiveData.map (source)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With