Skip to content

Instantly share code, notes, and snippets.

@tfcporciuncula
Created November 29, 2018 22:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tfcporciuncula/3b7da90bd42bd61154ff6c536cc5a873 to your computer and use it in GitHub Desktop.
Save tfcporciuncula/3b7da90bd42bd61154ff6c536cc5a873 to your computer and use it in GitHub Desktop.
ViewModelFactory
class ViewModelFactory<VM : ViewModel> @Inject constructor(
private val viewModel: Lazy<VM>
) : ViewModelProvider.Factory {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel> create(modelClass: Class<T>) = viewModel.get() as T
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment