https://kotlinlang.org logo
#android
Title
# android
n

Nizzle94

09/15/2018, 11:00 AM
I want to use Lambda expression but I am getting such error. Can anyone help ?
k

Kirill Rozhenkov

09/16/2018, 5:33 PM
this is what I do in my projects:
Copy code
fun <D : Any, T : LiveData<D>> T.observeWith(owner: LifecycleOwner, receiver: (D) -> Unit) {
    observe(owner, Observer<D> {
        if (it != null) {
            receiver(it)
        }
    })
}
and then you can call this function in your code like this:
loginViewModel.progress().observeWith(this, this::onProgress)
n

Nizzle94

09/17/2018, 6:22 AM
Woow super thanks bro