title: Getting data out of a struct for use in a table view
body: <p>I'm unable to get a struct containing vars loaded from JSON into a format suitable for a table view</p>
  
  <p>I've been playing around with this code for a while, done plenty of reading but I'm just plain stuck. I can get data from the server fine and print it to the console. I notice that the data is printed as KEY: "value" rather than "KEY":"value" and that might have something to do with it. Also as the code is right now I can count the number of rows correctly and display the value of FIRST in the table view. What I can't figure out is how to access the other variables for display. Any help is greatly appreciated!</p>
  
  <pre><code>import Cocoa
  
  class ViewController: NSViewController, NSTableViewDelegate, NSTableViewDataSource {
  
  static var globalPatientInstance: [Patient] = []
  
  var gotJSON: ([Patient], Error?) -&gt; Void = { (patients, error) in
      print("patients from gotJSON: \(patients)")
  
      globalPatientInstance = patients
  
      // this returns an error: "Type 'Patient' does not conform to protocol 'Sequence'"
      /*
       for (key, value) in patients[0] {
       println("\(key) -&gt; \(value)")
       tableArray.append(Objects(sectionName: key, sectionObjects: value))
       }
       */
      print("patients from gotJSON: \(globalPatientInstance[0])")
  }
  
  @IBOutlet var tableView: NSTableView!
  @IBAction func button(_ sender: Any) {
      self.tableView.reloadData()
  }
  
  
  override func viewDidLoad() {
      super.viewDidLoad()
      // Do any additional setup after loading the view, typically from a nib.
  
      self.tableView.delegate = self as NSTableViewDelegate
      self.tableView.dataSource = self
  
      let url = URL(string: "http://172.16.1.25/backend/returnA")
      let returnA = URLRequest(url: url!)
  
      retrieveJSON(with: returnA, completionHandler: gotJSON)
      self.tableView.reloadData()
  }
  
  
  func retrieveJSON(with request: URLRequest, completionHandler: @escaping ([Patient], Error?) -&gt; Void) {
  
      // set up the session
      let config = URLSessionConfiguration.default
      let session = URLSession(configuration: config)
  
      // make the request
      let task = session.dataTask(with: request as URLRequest) {
  
          // completion handler argument
          (data, response, error) in
  
          // completion handler
          guard let data = data else {
              print("Did not recieve data")
              completionHandler([], error)
              return
          }
          do {
              let decoder = JSONDecoder()
              let patients = try decoder.decode(Array&lt;Patient&gt;.self, from: data)
              // print(Patient)
              completionHandler(patients, error)
          }
          catch let err {
              print("Err", err)
              completionHandler([], error)
          }
      }
      task.resume()
  }
  
  
  func numberOfRows(in tableView: NSTableView) -&gt; Int {
      return ViewController.globalPatientInstance.count
  }
  
  func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -&gt; NSView? {
  
      var result: NSTableCellView
  
  
      result = tableView.makeView(withIdentifier: (tableColumn?.identifier)!, owner: self) as! NSTableCellView
  
      result.textField?.stringValue = ViewController.globalPatientInstance[row].FIRST
  
      return result
  }
  }
  </code></pre>
  
  <p>This code runs fine. The array contains three structs and the value of FIRST is successfully displayed in the table view when the button is pressed.</p>