In other words, if I have a process that continuously runs, but users can change parameters on the GUI that effect the process operation characteristics, where is a better place to put the process, in a NSThread or NSTimer?
In other words, if I have a process that continuously runs, but users can
Share
While
NSThreadandNSTimerare two separate things for different needs, lets compare the two functions:Using
NSThread:Using
NSTimer:Now, if we want to something only once,
NSThreadis the way to go, as shown in the following:Now, for the
NSTimervariant:The reason for this is that we have complete control over the thread while using a
NSThread, but if using aNSTimer, than we are executing inside aNSRunLoopwhich may freeze the UI if any heavy lifting is done inside. THAT is the advantage of aNSThreadover aNSTimer.You are also guaranteed that a
NSThreadthat is detached is executed immediately, with aNSTimer, which is based on NSRunLoop, cannot, as it may or may not be able to execute immediately.There is a 3rd alternative (well technically a fourth too,
pthreads, but I will ignore that for now),GCD, but I would suggest you RTFM on that, as it’s too broad of a topic to cover in this post.