xcode - iOS: How to use swift to add an infinite loop and a thread with time interval?
巴扎黑
巴扎黑 2017-05-31 10:32:00
0
1
659

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?

巴扎黑
巴扎黑

reply all (1)
过去多啦不再A梦

I confirmed in the comments that the subject of the question istarget: selfAn error was reported here.

The following are the questions after the question:

Oh yes, the controller has not been initialized at that time, thank you. Can you also ask me again what is the use of this target: variable? I only know that most targets fill in self, but I don’t know what the purpose of filling in self is, it is setting Agent?

A simple understanding is where the following parameterselectorbelongs.
Generally,selectorpoints to a certain method in a certain class. Whenlet displaylink = CADisplayLink(target: self, selector: #selector(step))is written in the same class, naturallytargetisself.

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!