nstimer

How can I use Timer (formerly NSTimer) in Swift?

拈花ヽ惹草 提交于 2019-11-26 00:32:11
问题 I tried var timer = NSTimer() timer(timeInterval: 0.01, target: self, selector: update, userInfo: nil, repeats: false) But, I got an error saying \'(timeInterval: $T1, target: ViewController, selector: () -> (), userInfo: NilType, repeats: Bool) -> $T6\' is not identical to \'NSTimer\' 回答1: This will work: override func viewDidLoad() { super.viewDidLoad() // Swift block syntax (iOS 10+) let timer = Timer(timeInterval: 0.4, repeats: true) { _ in print("Done!") } // Swift >=3 selector syntax

How do I use NSTimer?

青春壹個敷衍的年華 提交于 2019-11-25 22:21:47
问题 Locked . This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions. How do I use an NSTimer ? Can anyone give me step by step instructions? 回答1: Firstly I'd like to draw your attention to the Cocoa/CF documentation (which is always a great first port of call). The Apple docs have a section at the top of each reference article called "Companion Guides", which lists guides for the topic

@selector() in Swift?

核能气质少年 提交于 2019-11-25 21:49:23
问题 I\'m trying to create an NSTimer in Swift but I\'m having some trouble. NSTimer(timeInterval: 1, target: self, selector: test(), userInfo: nil, repeats: true) test() is a function in the same class. I get an error in the editor: Could not find an overload for \'init\' that accepts the supplied arguments When I change selector: test() to selector: nil the error disappears. I\'ve tried: selector: test() selector: test selector: Selector(test()) But nothing works and I can\'t find a solution in