Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- class ViewController: UIViewController {
- @IBOutlet weak var listTableView: UITableView!
- let URL_GET_PERSONAGE = "http://somesite.net/somescript.php"
- var firstnames: [String] = []
- var lastnames: [String] = []
- override func viewDidLoad() {
- super.viewDidLoad()
- let url = URL(string: URL_GET_PERSONAGE)
- do{
- let allContactsData = try Data(contentsOf: url!)
- let allContacts = try JSONSerialization.jsonObject(with: allContactsData, options: JSONSerialization.ReadingOptions.allowFragments) as! [String : AnyObject]
- if let arrJSON = allContacts["teams"] as? NSArray{
- for index in 0..<arrJSON.count{
- let aObject = arrJSON[index] as? [String : AnyObject]
- firstnames.append(aObject?["fname"] as! String)
- lastnames.append(aObject?["lname"] as! String)
- }
- print(firstnames)
- print(lastnames)
- listTableView.reloadData()
- }
- }
- catch {
- }
- }
- func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
- return self.firstnames.count;
- }
- func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
- {
- let cell: UITableViewCell! = self.listTableView.dequeueReusableCell(withIdentifier: "BasicCell", for: indexPath as IndexPath) as UITableViewCell!
- cell.textLabel?.text = self.firstnames[indexPath.row]
- return cell
- }
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- }
- }
- DispatchQueue.main.async(execute: {
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement