Created
June 12, 2020 16:03
-
-
Save stevencurtis/9c2ee3d0996a9084bfebeea7c65f8fef to your computer and use it in GitHub Desktop.
InitialViewModel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final class InitialViewModel { | |
private var networkManager: HTTPManagerProtocol? | |
init(coordinator: RootCoordinator?, networkManager: HTTPManagerProtocol) { | |
self.networkManager = networkManager | |
} | |
func fetchData(completion: @escaping (Result<[InitialModel], Error>) -> Void) { | |
networkManager?.get(url: URL(string: "NOURL")!, completionBlock: { result in | |
DispatchQueue.main.async { | |
switch result { | |
case .failure(let error): | |
completion(.failure(error)) | |
case .success(let data): | |
if let str = String(data: data, encoding: .utf8) { | |
let model = InitialModel(dataString: str) | |
completion(.success([model])) | |
} | |
} | |
} | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment