It can be implemented simply to this extent:
Define a bool type variable. This variable will be judged every time it loops. If it is true, print(666) will be printed, and the thread will sleep for 1s, and then repeat the cycle. .
I tried GCD's .concurrentPerform, but it can only execute a certain number, it's not really an infinite loop, and I don't know how to set the time interval.
There is also an NStimer method on the Internet, but I don't know which framework has been imported, and There is no NSTimer class (Swift project).
I tried Cadisplaylink and the problem has been solved, but when initializing it as a global variable,
let displaylink = CADisplayLink(target: self,
selector: #selector(step))
An error will be reported, why?
I confirmed in the comments that the subject of the question is
target: self
An error was reported here.The following are the questions after the question:
A simple understanding is where the following parameter
selector
belongs.Generally,
selector
points to a certain method in a certain class. Whenlet displaylink = CADisplayLink(target: self, selector: #selector(step))
is written in the same class, naturallytarget
isself
.