title: swift: show UIActivityIndicatorView when file unzipping
body: <p>I use this code to download my files and show progress of downloading in my label.</p>
  
  <p>my code:</p>
  
  <pre><code>func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {
  
      let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! MasterViewCell
  
      let cellFilePath = "\(indexPath.section)\(indexPath.row).zip"
      let indexOfTask = allDownloadTasks.index { (task:URLSessionDownloadTask) -&gt; Bool in
          return task.currentRequest?.url?.lastPathComponent == cellFilePath
      }
  
      if indexOfTask == nil {
  
          //cell.label?.isHidden = true
      }
      return cell
  }
  
  func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { 
  
      let path = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask, true)
      let documentDirectoryPath:String = path[0]
      let fileManager = FileManager()
      let destinationURLForFile = URL(fileURLWithPath: documentDirectoryPath.appendingFormat("/file.png"))
  
       if fileManager.fileExists(atPath: destinationURLForFile.path){
           animation()
       } else {
  
           let url = URL(string: "link")!
           let downloadTaskLocal = self.backgroundSession.downloadTask(with: url)
           self.allDownloadTasks.append(downloadTaskLocal) // Add a new task to the array
           downloadTaskLocal.resume()
  
           cell.label?.frame = CGRect(x: 70, y: 128, width: 82, height: 21)
           cell.label?.isHidden = false
  
       }
  }
  
  func urlSession(_ session: URLSession,
                      downloadTask: URLSessionDownloadTask,
                      didWriteData bytesWritten: Int64,
                      totalBytesWritten: Int64,
                      totalBytesExpectedToWrite: Int64){
  
          DispatchQueue.main.async(execute: {() -&gt; Void in
  
              if let visibleIndexPath = self.collectionView?.indexPathsForVisibleItems {
                  for visibleIndexPath in visibleIndexPath {
                      if (downloadTask.currentRequest?.url?.lastPathComponent == "\(visibleIndexPath.section)\(visibleIndexPath.row).zip") {
  
                          var myCell = self.collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: visibleIndexPath) as! MasterViewCell
                          myCell = self.collectionView?.cellForItem(at: visibleIndexPath) as! MasterViewCell
  
                          myCell.label.text = "\(Int(CGFloat(totalBytesWritten) / CGFloat(totalBytesExpectedToWrite) * 100.0))%"
  
                      if myCell.label?.text == "100%" {
                          myCell.label?.isHidden = true
                          myCell.activityIndicator?.isHidden = true
                          myCell.activityIndicator?.startAnimating()
                      }
  
                      }
                  }
              }
          })
      }
  </code></pre>
  
  <p>I have this code to unzip my file:</p>
  
  <pre><code>func urlSession(_ session: URLSession,
                  downloadTask: URLSessionDownloadTask,
                  didFinishDownloadingTo location: URL){
  
      let fileName = downloadTask.originalRequest?.url?.lastPathComponent
      let path = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask, true)
      let documentDirectoryPath:String = path[0]
      let fileManager = FileManager()
      let destinationURLForFile = URL(fileURLWithPath: documentDirectoryPath.appendingFormat("/\(String(describing: fileName!))"))
  
      do {
          try fileManager.moveItem(at: location, to: destinationURLForFile)
      }catch{
          print("error")
      }
  
      let indexOfComplatedTask = allDownloadTasks.index(of: downloadTask)
      if indexOfComplatedTask != nil {
  
          SSZipArchive.unzipFile(atPath: documentDirectoryPath.appendingFormat("/\(String(describing: fileName!))"), toDestination:documentDirectoryPath, delegate:self)
  
          do {
              try fileManager.removeItem(atPath: documentDirectoryPath.appendingFormat("/\(String(describing: fileName!))"))
          }
          catch let error as NSError {
              print("Ooops! Something went wrong: \(error)")
          }
  
      }
  }
  </code></pre>
  
  <p>I want to show my <code>activityIndicator</code> with start animation when file unzipping and stop animation and remove it after file stoped unzipping. Also I create label and activityIndicator in storyboard. </p>
  
  <p>How to do it?????</p>