Created
January 5, 2019 10:58
-
-
Save thanapongp/0a80520bafa7b2da09b4a9d0b98f17c0 to your computer and use it in GitHub Desktop.
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
private func filterUser(for searchText: String) { | |
if searchText.isEmpty { | |
return | |
} | |
let githubServiceProvider = MoyaProvider<GithubService>() | |
githubServiceProvider.request(.searchUsers(query: searchText), completion: { [weak self] result in | |
switch result { | |
case .success(let response): | |
self?.processResponse(response) | |
case .failure(let error): | |
print("Error: \(error)") | |
} | |
}) | |
} | |
private func processResponse(_ response: Moya.Response) { | |
let jsonObj = JSON(response.data) | |
users = jsonObj["items"].arrayValue.map { try! User(json: $0) } | |
tableView.reloadData() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment