title: How to pass IBOutlet between two classes?
body: <p>I have a class for managing <code>AVPlayer</code> and <code>ViewController</code> showing <code>AVPlayer</code>. In <code>ViewController</code> I have 3 <code>IBOutlets</code>:</p>
  
  <pre><code>@IBOutlet weak var playButton: UIButton!
  @IBOutlet weak var progressBar: UIProgressView!
  @IBOutlet weak var timerLabel: UILabel!
  </code></pre>
  
  <p>The problem is I can't figure out how to pass <code>IBOutlets</code> from <code>ViewController</code> to my player managing class. I always get <code>nil</code> and </p>
  
  <blockquote>
    <p>fatal error: unexpectedly found nil while unwrapping an Optional value</p>
  </blockquote>
  
  <p>when initialising <code>progressBar</code>, <code>timerLabel</code> or <code>playButton</code>.</p>
  
  <p>Here is some code from my player managing class:</p>
  
  <pre><code>import UIKit
  import AVFoundation
  
  class RecordsAudioPlayer: NSObject
  {
      var player = AVPlayer()
      var timerUpdateAudioProgressView = Timer()
      var timerUpdateTime = Timer()
      var isPlaying: Bool = false
  </code></pre>
  
  <p>...</p>
  
  <pre><code>func updateAudioProgressView()
      {
          let storyboard = UIStoryboard(name: "Main", bundle: nil)
          let vc = storyboard.instantiateViewController(withIdentifier: "callRecords") as! CallRecordsViewController
  
          let progressBar = vc.progressBar! 
          print("method fired: updateAudioProgressView ", NSDate.init(timeIntervalSinceNow: 0).description)
          if isPlaying
          {
              let currentPlayerItem = player.currentItem
              let duration = Float((currentPlayerItem?.asset.duration.value)!)/Float((currentPlayerItem?.asset.duration.timescale)!)
              let currentTime = Float(player.currentTime().value)/Float(player.currentTime().timescale)
              progressBar.setProgress(Float(currentTime/duration), animated: false)
          }
      }
  
      func updateTime()
      {
          let storyboard = UIStoryboard(name: "Main", bundle: nil)
          let vc = storyboard.instantiateViewController(withIdentifier: "callRecords") as! CallRecordsViewController
          let timerLabel: UILabel! = vc.timerLabel! //***I get exception here
          print("method fired: updateTime ", NSDate.init(timeIntervalSinceNow: 0).description)
          let currentTime = Int64(player.currentTime().value)/Int64(player.currentTime().timescale)
          let minutes = currentTime / 60
          let seconds = currentTime - minutes * 60
          timerLabel.text = String(format: "%02d : %02d", Int(minutes), Int(seconds))
      }
  </code></pre>