title: Image download in UITableView with UIProgressView Indicator
body: <p>I want to show progress indicator while Asynchronously downloading Image.</p>
  
  <p>I have done it with single image.</p>
  
  <p>But, How I will achieve this in tableView?.Because i'm using <strong>NSURLSessionDownloadDelegate</strong> and getting progress in <strong>URLSession</strong> delegate method.</p>
  
  <p>But,How to perform this in tableView where cell's will be reused,different cell's have different images,all of them will have different progress values...?</p>
  
  <p>Here is my code.</p>
  
  <pre><code>class ViewController: UIViewController,NSURLConnectionDataDelegate,NSURLSessionDownloadDelegate {
  
  var session:NSURLSession?
  var downloadTask:NSURLSessionDownloadTask?
  var downloadURLString = "imageURL"
  
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
  
      var configuration:NSURLSessionConfiguration = NSURLSessionConfiguration.backgroundSessionConfigurationWithIdentifier("com.app.POCWhatsappLoadingIndicator")
  
      configuration.allowsCellularAccess = true
  
      session = NSURLSession(configuration: configuration, delegate: self, delegateQueue: nil)
  
      var downloadURL:NSURL = NSURL(string: downloadURLString)!
  
      var request:NSURLRequest = NSURLRequest(URL: downloadURL)
  
      downloadTask = self.session?.downloadTaskWithRequest(request)
  
      downloadTask?.resume()
  
  }
  </code></pre>
  
  <p><strong>Delegate Methods</strong></p>
  
  <pre><code>func URLSession(session: NSURLSession, downloadTask: NSURLSessionDownloadTask, didFinishDownloadingToURL location: NSURL){
  
      var fileManager:NSFileManager = NSFileManager.defaultManager()
      var URLs:NSArray = fileManager.URLsForDirectory(NSSearchPathDirectory.DocumentDirectory, inDomains: NSSearchPathDomainMask.UserDomainMask)
      var documentsDirectory:NSURL = URLs.objectAtIndex(0) as NSURL
      var fromURL:NSURL = downloadTask.originalRequest.URL
      var destinationURL:NSURL = documentsDirectory.URLByAppendingPathComponent(fromURL.lastPathComponent!)
      var error:NSError?
  
  
      fileManager.removeItemAtURL(destinationURL, error: nil)
  
      var success:Bool = fileManager.copyItemAtURL(location, toURL: destinationURL, error: &amp;error)
  
      if(success){
  
  
          dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), {
  
              var image:UIImage = UIImage(contentsOfFile: destinationURL.path!)!
              UIGraphicsBeginImageContext(CGSizeMake(1, 1))
              var context:CGContextRef = UIGraphicsGetCurrentContext()
              CGContextDrawImage(context, CGRectMake(0, 0, 1, 1), image.CGImage)
              UIGraphicsEndImageContext()
  
              dispatch_sync(dispatch_get_main_queue(), {
  
              self.IBDownloadedImage.image = image
  
              })  
          })  
      }else{
            println("File Copy failed: \(error)")
      }
  }
  
  
  func URLSession(session: NSURLSession, downloadTask: NSURLSessionDownloadTask, didWriteData bytesWritten: Int64, totalBytesWritten: Int64, totalBytesExpectedToWrite: Int64){
  
      var progress:Float = ((Float(totalBytesWritten)/Float(totalBytesExpectedToWrite)))
  
      dispatch_async(dispatch_get_main_queue(), {
  
          self.updateProgress(progress)
  
      })
  
  }
  </code></pre>
  
  <p><strong>Custom Methods</strong></p>
  
  <pre><code>func updateProgress(progress:Float){
  
      if(progress &lt; 1.0){
  
          self.IBProgressView.setProgress(progress, animated: true)
          }
      }
  </code></pre>
  
  <p>That works fine for Single image.
  But how to do for <strong>UITableView.</strong></p>
  
  <p>Thanks.</p>