Skip to content

Instantly share code, notes, and snippets.

@thanapongp
Created January 5, 2019 10:58
Show Gist options
  • Save thanapongp/0a80520bafa7b2da09b4a9d0b98f17c0 to your computer and use it in GitHub Desktop.
Save thanapongp/0a80520bafa7b2da09b4a9d0b98f17c0 to your computer and use it in GitHub Desktop.
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