After upgrading the lifecycle dependency from 2.6.0-alpha04
to 2.6.0-beta01
I got Unresolved reference: Transformations and it can't import androidx.lifecycle.Transformations
class.
import androidx.lifecycle.Transformations
...
var myList: LiveData<List<Bookmark>> = Transformations.switchMap(
bookMarkType
) { input: Int? ->
when (input) {
ARTICLE_BOOKMARK -> return@switchMap repository.articleBookmarks
WEBSITE_BOOKMARK -> return@switchMap repository.websiteBookmarks
LINK_BOOKMARK -> return@switchMap repository.linkBookmarks
}
repository.websiteBookmarks
}
As of 2.6.0-alpha05 version:
So, instead of using
Transformations
, you need to use the extension function directlymyLiveData.switchMap
ormyLiveData.map
So, to fix this use: