Skip to content

Instantly share code, notes, and snippets.

@dmytro-anokhin
Created December 10, 2019 21:14
Show Gist options
  • Save dmytro-anokhin/3f5ee0452d9fa230690c0cdc045d961a to your computer and use it in GitHub Desktop.
Save dmytro-anokhin/3f5ee0452d9fa230690c0cdc045d961a to your computer and use it in GitHub Desktop.
struct PostsDataProviderA: DataProvider {
let networkService: NetworkingA
let userService: UserService
func fetchPosts(withURL url: URL, completion: @escaping (Result<[Post], Error>) -> Void) {
networkService.loadJSON(withURL: url, type: [Post].self, completion: completion)
}
func fetchUser(withId id: Int, completion: @escaping (User?) -> Void) {
userService.getUser(withId: id, completion: completion)
}
}
struct PostsDataProviderB: DataProvider {
let networkService: NetworkingB
let userService: UserService
func fetchPosts(withURL url: URL, completion: @escaping (Result<[Post], Error>) -> Void) {
networkService.load(url, type: [Post].self, completion: completion)
}
func fetchUser(withId id: Int, completion: @escaping (User?) -> Void) {
userService.getUser(withId: id, completion: completion)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment