Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. import UIKit
  2.  
  3. class ViewController: UIViewController {
  4.  
  5. @IBOutlet weak var listTableView: UITableView!
  6. let URL_GET_PERSONAGE = "http://somesite.net/somescript.php"
  7. var firstnames: [String] = []
  8. var lastnames: [String] = []
  9.  
  10. override func viewDidLoad() {
  11. super.viewDidLoad()
  12. let url = URL(string: URL_GET_PERSONAGE)
  13. do{
  14. let allContactsData = try Data(contentsOf: url!)
  15. let allContacts = try JSONSerialization.jsonObject(with: allContactsData, options: JSONSerialization.ReadingOptions.allowFragments) as! [String : AnyObject]
  16. if let arrJSON = allContacts["teams"] as? NSArray{
  17. for index in 0..<arrJSON.count{
  18. let aObject = arrJSON[index] as? [String : AnyObject]
  19. firstnames.append(aObject?["fname"] as! String)
  20. lastnames.append(aObject?["lname"] as! String)
  21.  
  22. }
  23. print(firstnames)
  24. print(lastnames)
  25. listTableView.reloadData()
  26. }
  27. }
  28. catch {
  29. }
  30. }
  31. func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
  32. return self.firstnames.count;
  33. }
  34. func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
  35. {
  36. let cell: UITableViewCell! = self.listTableView.dequeueReusableCell(withIdentifier: "BasicCell", for: indexPath as IndexPath) as UITableViewCell!
  37. cell.textLabel?.text = self.firstnames[indexPath.row]
  38.  
  39. return cell
  40. }
  41. override func didReceiveMemoryWarning() {
  42. super.didReceiveMemoryWarning()
  43. }
  44. }
  45.  
  46. DispatchQueue.main.async(execute: {
  47.  
  48. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement