Created
May 5, 2016 13:57
-
-
Save seyhunak/1ca235dc41035fccb4a78f5fe66307f1 to your computer and use it in GitHub Desktop.
Moya - Sample
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
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