0

So the timer works once but after the first time it doesnt work anymore... What's the problem and how can it be fixed? Thanks!

override func viewDidLoad() {
        super.viewDidLoad()

 let myTimer : Timer = Timer.scheduledTimer(timeInterval: 7, target: self, selector: (selector: "functionOne"), userInfo: nil, repeats: true)
        }
    }
    func functionOne()
    {
       print("hello")

    }
rmaddy
  • 314,917
  • 42
  • 532
  • 579
Phillip
  • 193
  • 10
  • 1
    FYI - your Swift 3 selector syntax is incorrect. See http://stackoverflow.com/questions/24007650/selector-in-swift – rmaddy Nov 04 '16 at 16:56

1 Answers1

3

Try this code:

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    Timer.scheduledTimer(timeInterval: 7.0, target: self, selector: #selector(functionOne), userInfo: nil, repeats: true)

}

func functionOne () { 
   print("hello") 
}

Output:

enter image description here

Joe
  • 8,868
  • 8
  • 37
  • 59