Created
May 22, 2019 17:17
-
-
Save polson/7f8d9e13ab8573c8e48c90e73efef4b6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
@Suppress("UNCHECKED_CAST") | |
private inline fun <reified T : ViewModel> createViewModel(key: String, crossinline initializer: () -> T): T { | |
val factory = object : ViewModelProvider.NewInstanceFactory() { | |
override fun <T : ViewModel?> create(modelClass: Class<T>): T = initializer() as T | |
} | |
return ViewModelProviders.of(activity, factory).get(key, T::class.java) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment