Created
April 6, 2022 08:19
-
-
Save happysingh23828/93969a7bd8617b92bee882b54faffe06 to your computer and use it in GitHub Desktop.
ViewModel Factory Extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun <T : ViewModel?> T.createFactory(): ViewModelProvider.Factory { | |
val viewModel = this | |
return object : ViewModelProvider.Factory { | |
@Suppress("UNCHECKED_CAST") | |
override fun <T : ViewModel?> create(modelClass: Class<T>): T = viewModel as T | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment