title: (Swift2.3)Accessing class instance from another class
body: <p>New to Swift. I am trying to control the playback of background music on my app. I currently have the music starting up in my MainTabController. It plays as expected when I navigate through the rest of the VCs. I would like it to stop when certain VCs are shown, however.</p>
  
  <p>I have my MusicHelper class set up.</p>
  
  <pre><code>class MusicHelper {
  static let sharedHelper = MusicHelper()
  var audioPlayer: AVAudioPlayer?
  
  func playBackgroundMusic(file : String, repeats : Int) {
      let aSound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource(file, ofType: "mp3")!)
      do {
          audioPlayer = try AVAudioPlayer(contentsOfURL:aSound)
          audioPlayer!.numberOfLoops = repeats
          audioPlayer!.prepareToPlay()
          audioPlayer!.play()
      } catch {
          print("Cannot play the file")
      }
  }
  
  func togglePlayer(){
      if((audioPlayer?.playing) == true){
          audioPlayer?.stop()
      }else{
          audioPlayer?.play()
      }
  }
  }
  </code></pre>
  
  <p>How I start the music initially in my MainTabController:</p>
  
  <pre><code>class MainTabController: UINavigationController {
  
  var bgMusic : MusicHelper = MusicHelper()
  
  override func viewDidLoad() {
      super.viewDidLoad()
      // other code
      bgMusic.playBackgroundMusic("music_background", repeats: -1)
  }   
  }
  </code></pre>
  
  <p>I am trying to access this same instance of bgMusic, but it is returning nil. My assumption is that I am actually making a new instance of the MainTabController? If so, how would I go about accessing that same instance of MusicHelper?</p>
  
  <pre><code>class VideoViewController: OrientationLockedVC {
      //Other code
      var mVC : MainTabController = MainTabController()
  
      func onImage() {
          //other code
          mVC.bgMusic.audioPlayer!.stop()
  
          // other code
      }
  
  }
  </code></pre>
  
  <p>I'm not getting any explicit errors, but if I set a break point I can clearly see that the audioController is nil.</p>
  
  <p>Thanks</p>