Guest User

Untitled

a guest
Nov 24th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. {
  2. "login": "mojombo",
  3. "id": 1,
  4. "repos_url": "https://api.github.com/users/mojombo/repos"
  5. }
  6.  
  7. // don't forget
  8. import Alamofire
  9. import SwiftyJSON
  10.  
  11. // initialise variables
  12.  
  13. var fetchResult = [[String:AnyObject]]()
  14. struct User{
  15. var name:String?
  16. var id:Int?
  17. var repo_url:String
  18.  
  19. init(name:String,id:Int,repoURL:String){
  20.  
  21. self.name = name
  22. self.id = id
  23. self.repo_url = repoURL
  24.  
  25. }
  26. }
  27.  
  28. let user = [User]
  29.  
  30.  
  31. fun getData(){
  32.  
  33. Alamofire.request("https://api.github.com/users").responseJSON { (responseData) -> Void in
  34. if((responseData.result.value) != nil) {
  35. let response = JSON(responseData.result.value!)
  36. print(response)
  37.  
  38. if let resData = response.arrayObject {
  39.  
  40. self.fetchResult = resData as! [[String:AnyObject]]
  41.  
  42. print(self.fetchResult)
  43. }
  44.  
  45. for item in self.fetchResult {
  46.  
  47. print(item)
  48.  
  49. guard let login = item["login"] as! String else {return}
  50.  
  51. guard let id = item["id"] as! Int else {return}
  52.  
  53. guard let repos_url = item["repos_url"] as! String else {return}
  54.  
  55. let gitUser = User(name: login , id: id, repoURL: repos_url)
  56. self.user.append(gitUser)
  57. }
  58.  
  59. }
  60. if self.user.count>0{
  61. self()
  62. }
  63.  
  64. func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: IndexPath) {
  65.  
  66. let selected = user[indexPath.row]
  67.  
  68.  
  69. let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
  70. let newViewController =
  71. storyBoard.instantiateViewController(withIdentifier: "SecondVC") as! SecondVC
  72. newViewController.data = selected
  73. self.navigationController?.pushViewController(newViewController, animated: true)
  74.  
  75. }
Add Comment
Please, Sign In to add comment