title: Make instance wait until called functions are complete - Swift
body: <p>I apologise in advance if this has already been answered but as you can probably tell from the title I wasn't really sure how to describe the issue and a answer to a similar question I found wasn't helpful.</p>
  
  <p>I'm attempting to make an instance of "Coupon" that has its properties loaded from an SQL database after passing an id to the database in the init method.</p>
  
  <p>My issue is when I call then init method from a different viewController class it will return the instance with the default string values of "" as the data from the NSURLConnection hasn't been/decoded before returning to the viewContoller.</p>
  
  <p>Im looking for a solution for to some how make the init method wait until the fields are loaded. </p>
  
  <p>Coupon class relevant properties:</p>
  
  <pre><code>var webData: NSMutableData?
  
  var id: Int
  var name: String = ""
  var provider: String = ""
  var details: String = ""
  </code></pre>
  
  <p>Coupon class relevant methods:</p>
  
  <pre><code>convenience init(id: Int) {
  
      self.init()
      self.id = id
  
      self.selectSQL(id) //passes id to server and returns all other varibles
  
  }
  
     func selectSQL(id: Int) {
  
      let url = NSURL(string: "http://wwww.website.php?id=\(id)") // acess php page
      let urlRequest = NSURLRequest(URL: url!)
      let connection = NSURLConnection(request: urlRequest, delegate: self)
  
  }
  
  func connection(connection: NSURLConnection, didReceiveResponse response: NSURLResponse) {
  
      webData = NSMutableData()
  
  }
  
  func connection(connection: NSURLConnection, didReceiveData data: NSData) {
  
      webData?.appendData(data)
  
  }
  
  func connectionDidFinishLoading(connection: NSURLConnection) {
  
      let result = NSJSONSerialization.JSONObjectWithData(webData!, options: .AllowFragments, error: nil) as? NSArray
  
      let resultDict = result?[0] as? NSDictionary
  
      if let dict = resultDict {
  
          name = dict.objectForKey("name") as! String
          provider = dict.objectForKey("provider") as! String
          details = dict.objectForKey("details") as! String
  
      }
  </code></pre>