title: Proper way to pull JSON API response and store or reference it in Swift?
body: <p>I'm interested in knowing if there's a "proper" way to handle JSON responses from API requests.</p>
  
  <p>Right now I have a struct that contains a static var. In the AppDelegate I grab the JSON from a URL (using Alamofire). I am able to reference it later in different views, however I have read that there are better ways than a "struct hack" to handle this.</p>
  
  <p>My goal is to minimize the amount of calls, and only refresh when it's appropriate (ie. user "pulls down to refresh", "new object inserted into database", etc). Should this be how I handle it, or should I load different JSON responses on each new view, depending on what's required?</p>
  
  <p>Any direction is appreciated.</p>
  
  <hr>
  
  <p>Edit: Here's where I read that Structs were a "hack" for a "global variable". Maybe storing JSON in a struct is different than keeping a typical user variable in one. I don't know. See the second Answer's remarks.</p>
  
  <p><a href="https://stackoverflow.com/questions/24868120/how-to-create-global-variable-in-swift">Global Variables in Swift</a></p>
  
  <p>As for the Struct I have:</p>
  
  <p>In my <strong>jsonDataHolder.swift</strong> file:</p>
  
  <pre><code>struct jsonDataHolder {
      static var jsonData:AnyObject = []
  }
  </code></pre>
  
  <p>In my <strong>AppDelegate.swift</strong> file, I have the following in <strong>DidFinishLaunchingWithOptions</strong> section:</p>
  
  <pre><code>Alamofire.request(.GET, "http://xxxxxxxxxx.com/yyy", encoding: .JSON).responseJSON { (_, _, JSONData, _) in
      jsonDataHolder.jsonData = JSONData!
  }
  </code></pre>
  
  <p>Again, this all works fine. Just not sure if it's the "right" (if there is such a thing) way to do it.</p>