title: Update a UILabel using string value from another class in Swift
body: <p>How do I used a string value from a function in a another class to update an UILabel on my ViewController?
  Here is my code:</p>
  
  <p>View controller:</p>
  
  <p>import UIKit</p>
  
  <p>class ViewController: UIViewController, dataEnterdDelegate {</p>
  
  <pre><code>@IBOutlet weak var auaTempLabel: UILabel!
  
  override func viewDidLoad() {
      super.viewDidLoad()
      let weather2 = WeatherService2()
      weather2.getWeatherData("Oranjestad,AW") 
  }
  
  **func userDidEnterInformation(info: NSString)
  {
      testLabel!.text = info as String
  }**
  
  func setLabel2(information: String)
  {
      auaTempLabel.text = information
  }
  </code></pre>
  
  <p>The other class named WeatherService2 contain the following codes:</p>
  
  <pre><code>**protocol dataEnterdDelegate{
  func userDidEnterInformation(info:NSString)
  }**
  
  Class WeatherService2{
  var currentTempeture:String?
  let targetVC = ViewController()
  **var delegate: dataEnterdDelegate?**
  
  func getWeatherData(urlString:String)
  {
      let url = NSURL(string: urlString)!
      let sqlQuery =  "select * from weather.forecast where woeid in (select woeid from geo.places(1) where text=\"\(url)\")"
  
      let endpoint = "https://query.yahooapis.com/v1/public/yql?q=\(sqlQuery)&amp;format=json"
  
      let testString = (String(endpoint))
      getData(testString)
  }
  
  func getData(request_data: String)
  {
      let requestString:NSString = request_data.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())!
  
      let url_with_data = NSURL(string: requestString as String)!
      let task = NSURLSession.sharedSession().dataTaskWithURL(url_with_data){
          (data, response, error) in dispatch_async(dispatch_get_main_queue(), {
              if data == nil
              {
                  print("Failed loading HTTP link")
  
              }else{
                  self.setLabel(data!)
              }
          })
      }
      task.resume()
  
  
  
  }
  
  func setLabel(weatherData:NSData)
  {
      enum JSONErrors: ErrorType
      {
          case UserError
          case jsonError
      }
  
      do{
          let jsonResults = try NSJSONSerialization.JSONObjectWithData(weatherData, options: .AllowFragments)
  
          if let city = jsonResults["query"] as? NSDictionary
          {
              if let name = city["results"] as? NSDictionary
              {
                  if let channel = name["channel"] as? NSDictionary
                  {
                      if let item = channel["item"] as? NSDictionary
                      {
                          if let condition = item["condition"] as? NSDictionary
                          {
                              if let temp = condition["temp"] as? String
                              {
                                  setTemp(temp)
                                  **delegate!.userDidEnterInformation(temp)**   
                              }
                          }
                      }
                  }
  
              }
          }
      }
  
      catch {
          print("Failed to load JSON Object")
  
      }
  
  
  }
  
  
  func setTemp(tempeture:String)
  {
      self.currentTempeture = tempeture
  }
  
  func getTemp() -&gt;String
  {
      return self.currentTempeture!
  }
  </code></pre>
  
  <p>}</p>
  
  <p>The code runs fine and everything but I get an error "Fatal error: unexpectedly found nil while unwrapping an Optional value" when I try to update the UILabel in my ViewController. 
  When I used the <code>print("The return value is: "+information)</code> in the view controller class it print the return value correctly. 
  This is the reason I'm confused right now because I don't know why I still getting the "Fatal error: unexpectedly found nil while unwrapping an Optional value" when trying to use this value to update my UILabel.</p>
  
  <p>Can anyone help me with this problem?</p>
  
  <p>Thanks in advance</p>