How to add json data to array or similar using Swift
<p>I am fairly new to Swift and I am having a few issues with getting understanding how to do what I want to do.</p>

<p>I am currently testing some stuff with json.
What I am trying to do is to append the data I get from my json data into an array. And when my array contains the data I wish to present it to my UICollectionView. I am assuming that I should be using an array.</p>

<pre><code>import UIKit
import Foundation

class ViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {

    @IBOutlet weak var collectionView: UICollectionView!

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }

    func getData() {

        let path = "http://myurl/test.json"
        let url = URL(string: path)
        let session = URLSession.shared

        let task = session.dataTask(with: url!) { (data: Data?, response: URLResponse?, error: Error?) in

            let json = JSON(data: data!)

            for result in json["dokumentstatus"]["dokutskott"]["utskott"].array! {

                let punkter = result["punkt"].string!
                print("punkt: \(punkt)")

                let rubrik = result["rubrik"].string
                print("rubrik: \(rubrik)")

                let forslag = result["forslag"].string
                print("förslag: \(forslag)")
            }
        }

        task.resume()
    }

    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
        return //someArray.count
    }

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {

        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! CustomCollectionViewCell

        cell.customLabel.text = //Put the data form rubrik variable
            cell.customTW.text = //Put the data from foreleg variable

        return cell

    }
}
</code></pre>

<p>the function <code>getData()</code> gets the correct json data I just need help understanding how to put this data to an array.
(Also, I know I probably shouldn't be getting the data in the ViewController, but this is only a test.)</p>

<pre><code>import Foundation

class Information: NSObject {
    var punkter: String?
    var rubrik: String?
    var forslag: String?
}
</code></pre>

<p>I'm thinking that maybe I should be using an array that looks something like this:<code>var someArray = [Information]()</code>
But I do not know how to then use my <code>getData()</code>
Or maybe I should be using three different arrays, one for each of my json variables.</p>