Skip to content

Instantly share code, notes, and snippets.

@seyhunak
Created May 5, 2016 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seyhunak/1ca235dc41035fccb4a78f5fe66307f1 to your computer and use it in GitHub Desktop.
Save seyhunak/1ca235dc41035fccb4a78f5fe66307f1 to your computer and use it in GitHub Desktop.
Moya - Sample
GitHubProvider.request(.UserRepositories(username), completion: { result in
var success = true
var message = "Unable to fetch from GitHub"
switch result {
case let .Success(response):
do {
let json: NSArray? = try response.mapJSON() as? NSArray
if let json = json {
// Presumably, you'd parse the JSON into a model object. This is just a demo, so we'll keep it as-is.
self.repos = json
} else {
success = false
}
} catch {
success = false
}
self.tableView.reloadData()
case let .Failure(error):
guard let error = error as? CustomStringConvertible else {
break
}
message = error.description
success = false
}
if !success {
let alertController = UIAlertController(title: "GitHub Fetch", message: message, preferredStyle: .Alert)
let ok = UIAlertAction(title: "OK", style: .Default, handler: { (action) -> Void in
alertController.dismissViewControllerAnimated(true, completion: nil)
})
alertController.addAction(ok)
self.presentViewController(alertController, animated: true, completion: nil)
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment