title: How to call timer one time in application using swift?
body: <p>Hi all am developing a app using swift 2 in my app am updating current location for every x minutes so am using NSTimer am able to update location and everything works fine.In my app(first view controller) when a user successfully logged in and moves to second view controller in(second view controller) i wrote the function for updating location using NSTimer it works fine but when the user moves to third view controller and return to second view controller it again start updating location so i cant able to stop the timer twice it invalidate timer one time only other one keep on updating the location even after the users logged out.so please someone help me out to solve this problem.</p>
  
  <p>my second view controller:</p>
  
  <pre><code>class secondviewcontroller:UIViewController{
  </code></pre>
  
  <p>in view did load method:</p>
  
  <pre><code>  var appDelegate:AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
               appDelegate.timer = NSTimer.scheduledTimerWithTimeInterval(10.0, target: self, selector: #selector(timeToMoveOn), userInfo: nil, repeats: true)
  
   //i declared var timer:nstimer! in appdelegate.swift and i performed some function using nstimer
  </code></pre>
  
  <p>my third view controller:</p>
  
  <p>I created a button action for logout code is:</p>
  
  <pre><code>  var appDelegate:AppDelegate = (UIApplication.sharedApplication().delegate as?
              AppDelegate)!
           appDelegate.timer.invalidate()
  </code></pre>
  
  <p>Thanks in advance</p>
  
  <p>Hi all thank you for your support i found the answer for my question</p>
  
  <p>i just kept timer.invalidate() in two different methods according to my project</p>