Skip to content

Instantly share code, notes, and snippets.

@robotsquidward
Created September 30, 2020 12:49
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 robotsquidward/1113b64a7c822200ec27f747ed793a33 to your computer and use it in GitHub Desktop.
Save robotsquidward/1113b64a7c822200ec27f747ed793a33 to your computer and use it in GitHub Desktop.
fun createWithFactory(
create: () -> ViewModel
): ViewModelProvider.Factory {
return object : ViewModelProvider.Factory {
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
@Suppress("UNCHECKED_CAST")// Casting T as ViewModel
return create.invoke() as T
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment