Skip to content

Instantly share code, notes, and snippets.

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 JohnSundell/d6770d6ced11b53c2bf954bf2e4547bf to your computer and use it in GitHub Desktop.
Save JohnSundell/d6770d6ced11b53c2bf954bf2e4547bf to your computer and use it in GitHub Desktop.
class ModelLoader<T: Unboxable & Requestable> {
func load(completionHandler: (Result<T>) -> Void) {
networkService.loadData(from: T.requestURL) { data in
do {
try completionHandler(.success(unbox(data: data)))
} catch {
let error = ModelLoadingError.unboxingFailed(error)
completionHandler(.error(error))
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment