title: How to use variables outside ViewDidLoad( ) - Swift
body: <p>If I have declared a variable withing <code>ViewDidLoad()</code>. Is there a way to access that variable outside of <code>ViewDidLoad( )</code>?</p>
  
  <p>I have retrieved and stored the JSON data from an API. I am able to access the variable 'hourlyInfo' within the <code>ViewDidLoad( )</code>, but not outside of it. Should I use global variables? Or am I in approaching the problem wrongly to begin with?</p>
  
  <pre><code>eoverride func viewDidLoad() {
      super.viewDidLoad()
      // Do any additional setup after loading the view, typically from a nib.
  
      //getting the data from URL:
      let mainAddress = NSURL(string: "https:.......") 
  
  
      //Now, getting the data syncronously by creating a session object::
      let sharedSession = NSURLSession.sharedSession()
      let downloadTask: NSURLSessionDownloadTask =
      sharedSession.downloadTaskWithURL(mainAddress!, completionHandler: {
          (location:NSURL!, response:NSURLResponse!, error: NSError!) -&gt; Void in
  
          if error == nil {
              //Now, creating a dataObject for the task:
              let dataObject = NSData(contentsOfURL: location)
  
  
              //getting a formated dictionary of the data from URL:
              var weatherDictionary: NSDictionary = NSJSONSerialization.JSONObjectWithData(dataObject!, options: nil, error: nil) as NSDictionary //added '!' to NSdata for now
  
  
  
  
  
     var hourlyInfo = hourlyData(weatherDictionary: weatherDictionary) 
  
     println(hourlyInfo.hourPop1)//testing                         
  
  
          }
  
  
  
      })
  
      downloadTask.resume()
  </code></pre>