Skip to content

Instantly share code, notes, and snippets.

@AndreyPanov
Last active May 10, 2017 11:00
Show Gist options
  • Save AndreyPanov/05346ada24a875e1d4ee12c013e60cc0 to your computer and use it in GitHub Desktop.
Save AndreyPanov/05346ada24a875e1d4ee12c013e60cc0 to your computer and use it in GitHub Desktop.
final class Repository: Chainable {
var before: (()->())?
private let dataProdider: DataProvider
init(dataProdider: DataProvider = .init()) {
self.dataProdider = dataProdider
}
func getItem(onSuccess: @escaping (Item)->(), onError: @escaping (Error)->()) {
//background async request
dataProvider.request.items { [weak self] data, error in
self?.invoke()
if let item = ItemBuilder(with: data) {
onSuccess(item)
} else {
onError(error)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment