title: cannot change class variables while runtime swift
body: <p>That's an what I want to do. I want to change a class variable while the project is running and use that in player. For example, while the app is running when user plays a button the player will stop and change the URL and start again. How can I do it?</p>
  <p>EDIT: Question changed to avoid forum pollution.</p>
  <pre><code>let pa = PlayerAv()
  
  class PlayerAv
  {
      var audioLink = &quot;&quot;
      var player: AVPlayer
      init()
      {
          player = AVPlayer(URL: NSURL(string: self.audioLink))
      }
  }
  
  @IBAction func changeToSabiha() {
      pa.player.pause()
      PlayerAv().audioLink = &quot;http://someurl.com/bcd.pls&quot;
      println(&quot;\(pa.audioLink)&quot;)
      pa.player.play()
  }
  </code></pre>
  <p>//The whole code</p>
  <pre><code>import UIKit
  import AVFoundation
  import MediaPlayer
  import GoogleMobileAds
  
  
  class ViewController: UIViewController {
  
  
      @IBOutlet weak var statLabel: UILabel!
      @IBOutlet weak var ataturkButton: UIButton!
      @IBOutlet weak var sabihaButton: UIButton!
      @IBOutlet weak var esenbogaButton: UIButton!
      @IBOutlet weak var weatherButton: UIButton!
      @IBOutlet weak var statusLabel: UILabel!
      @IBOutlet weak var playButton: UIButton!
  
      var googleBannerView: GADBannerView!
  
  
  
  
      override func viewDidLoad() {
          super.viewDidLoad()
          // Do any additional setup after loading the view, typically from a nib.
          googleBannerView = GADBannerView(adSize: kGADAdSizeSmartBannerPortrait)
          googleBannerView.adUnitID = &quot;adunitIDXXXX&quot;
          googleBannerView.rootViewController = self
          var request: GADRequest = GADRequest()
          googleBannerView.loadRequest(request)
  
          googleBannerView.frame = CGRectMake(0, view.bounds.height - googleBannerView.frame.size.height, googleBannerView.frame.size.width, googleBannerView.frame.size.height)
          self.view.addSubview(googleBannerView!)
  
  
  
          //setTitle commands start
          statusLabel.text = &quot;Status: Not Playing&quot;
          playButton.setTitle(&quot;Play&quot;, forState: UIControlState.Normal)
          weatherButton.setTitle(&quot;Show Weather&quot;, forState: .Normal)
          ataturkButton.setTitle(&quot;Ataturk - LTBA&quot;, forState: .Normal)
          sabihaButton.setTitle(&quot;Sabiha Gökçen - LTFJ&quot;, forState: .Normal)
          esenbogaButton.setTitle(&quot;Esenboğa - LTAC&quot;, forState: .Normal)
          //setTitle commands end
  
  
  
  
  
          switch Reachability.isConnectedToNetwork() {
          case false :
              println(&quot;Internet connection FAILED&quot;)
              var alert = UIAlertView(title: &quot;No Internet Connection&quot;, message: &quot;Make sure your device is connected to the internet.&quot;, delegate: nil, cancelButtonTitle: &quot;OK&quot;)
              alert.show()
          default:
              println(&quot;Internet connection OK&quot;)
  
  
          }
  
  
      }//viewDidLoad() end
  
      let pa = PlayerAv().audioLink
  
      class PlayerAv
      {
          var audioLink:String = &quot;&quot;
          var player: AVPlayer
          init()
          {
              player = AVPlayer(URL: NSURL(string: self.audioLink))
          }
      }
  
  
      @IBAction func sliderValueChanged(sender: UISlider) {
          var currentValue = Float(sender.value)
          println(currentValue)
          PlayerAv().player.volume = currentValue
      }
  
  
      @IBAction func getWeatherWindow(sender: AnyObject) {
          UIApplication.sharedApplication().openURL(NSURL(string: &quot;somewebpage.com&quot;)!)
          println(&quot;Directed to weather page&quot;)
      }
  
  
  
  
  
      //Tower change statements start
  
      @IBAction func changeToAtaturk() {
          PlayerAv().player.pause()
          pa == &quot;http://someurl.com/def.pls&quot;
          println(&quot;\(pa)--a&quot;)
          PlayerAv().player.play()
      }
  
  
  
      @IBAction func changeToEsenboga() {
          PlayerAv().player.pause()
          PlayerAv().audioLink = &quot;http://someurl.com/bcd.pls&quot;
          println(&quot;\(pa)--a&quot;)
          PlayerAv().player.play()
      }
  
      @IBAction func changeToSabiha() {
          PlayerAv().player.pause()
          pa == &quot;http://someurl.com/abc.pls&quot;
          println(&quot;\(pa)--a&quot;)
          PlayerAv().player.play()
      }
  
  
      //Tower change statements end
  
  
  
  
      override func didReceiveMemoryWarning() {
  
          super.didReceiveMemoryWarning()
          // Dispose of any resources that can be recreated.
      }
  
  
      @IBAction func buttonPressed(sender: AnyObject) {
          toggle()
      }
  
  
      func toggle() {
          if playButton.titleLabel?.text == &quot;Play&quot; {
              playRadio()
              println(&quot;Playing&quot;)
              statusLabel.text = &quot;Status: Playing&quot;
          } else {
              pauseRadio()
              println(&quot;Paused&quot;)
              statusLabel.text = &quot;Status: Paused&quot;
          }
      }
  
      func playRadio() {
          PlayerAv().player.play()
          playButton.setTitle(&quot;Pause&quot;, forState: UIControlState.Normal)
  
      }
  
      func pauseRadio() {
          PlayerAv().player.pause()
          playButton.setTitle(&quot;Play&quot;, forState: UIControlState.Normal)
      }
  
      override func remoteControlReceivedWithEvent(event: UIEvent) {
          if event.type == UIEventType.RemoteControl {
              if event.subtype == UIEventSubtype.RemoteControlPlay {
                  println(&quot;received remote play&quot;)
                  playRadio()
              } else if event.subtype == UIEventSubtype.RemoteControlPause {
                  println(&quot;received remote pause&quot;)
                  pauseRadio()
              } else if event.subtype == UIEventSubtype.RemoteControlTogglePlayPause {
                  println(&quot;received toggle&quot;)
                  toggle()
              }
          }
      }
  }
  </code></pre>