title: swift invalidate timer doesn't work
body: <p>I have this problem for a few days now and I don't get what I am doing wrong. </p>
  
  <p>My application is basically just creating some timers. I need to stop them and create new ones. But at the moment stopping them doesn't work.</p>
  
  <pre><code>self.timer = NSTimer.scheduledTimerWithTimeInterval(timeInterval, target:self, selector: "timerDidEnd:", userInfo: "Notification fired", repeats: false)
  </code></pre>
  
  <p>That's my timer</p>
  
  <pre><code>func timerDidEnd(timer:NSTimer){
      createUnrepeatedAlarmWithUpdateInterval()
  }
  </code></pre>
  
  <p>Because my timer didn't want to stop I am currently using the unrepeated timer and start it myself after it stopped.</p>
  
  <pre><code>func stopAlarm() {
  
      if self.timer != nil {
          self.timer!.invalidate()
      }
      self.timer = nil
      self.timer = NSTimer()
  }
  </code></pre>
  
  <p>And that's how I stop my timer.</p>
  
  <pre><code>alarmManager.stopAlarm()
  alarmManager.createUnrepeatedAlarmWithUpdateInterval()
  </code></pre>
  
  <p>I call the <code>stopAlarm()</code> function before creating a new timer.</p>
  
  <p>I really don't know what I am doing wrong so I appreciate every answer :)</p>
  
  <pre><code>class AlarmManager: ViewController{
  
  private var timer : NSTimer?
  private var unrepeatedTimer : NSTimer?
  private let notificationManager = NotificationManager()
  private var current = NSThread()
  private let settingsViewController = SettingsViewController()
  
  func createRepeatedAlarmWithUpdateInterval(){
  
      var timeInterval:NSTimeInterval = settingsViewController.getUpdateIntervalSettings()
  
      if timer == nil{
      timer = NSTimer.scheduledTimerWithTimeInterval(timeInterval,
          target: self,
          selector: "repeatedTimerDidEnd:",
          userInfo: "Notification fired",
          repeats: true)
      }
  }
  func repeatedTimerDidEnd(repeatedTimer:NSTimer){
      ConnectionManager.sharedInstance.loadTrainings(settingsViewController.getServerSettings())
      createUnrepeatedAlarm(10)
  }
  
  func createUnrepeatedAlarm(timeInterval:Double){
  
      unrepeatedTimer = NSTimer.scheduledTimerWithTimeInterval(timeInterval,
          target: self,
          selector: "unrepeatedTimerDidEnd:",
          userInfo: "Notification fired",
          repeats: false)
  }
  func unrepeatedTimerDidEnd(unrepeatedTimer:NSTimer){
      notificationManager.createNotification(self, reminderType: NotificationManager.ITEMRATINGREMINDER)
      notificationManager.createNotification(self, reminderType: NotificationManager.ITEMREMINDER)
      print("UnrepeatedAlarm ended")
  }
  
  func stopAlarm(){
      print("StopAlarm triggered")
      if (timer != nil)
      {
          print("stoptimer executed")
          timer!.invalidate()
          timer = nil
      }
  
      if (unrepeatedTimer != nil)
      {
          unrepeatedTimer!.invalidate()
          unrepeatedTimer = nil
      }
  }
  }
  </code></pre>
  
  <p>Thats the whole code of this class. Maybe that helps :D</p>