Manisha Manisha - 1 year ago 62
iOS Question

how to start a global thread in swift

Is there any way to start and stop a thread in swift along with it making the thread global also so that it can used anywhere.

As shown below, this is how i create thread in swift

var objThrd = SimpleClass()
let thread = NSThread(target: objThrd , selector: "createSimpleObj", object: nil)

Please give an example if feasible. Or can we achieve this via NSOperation ?

Max Max
Answer Source

Use Grand Central Dispatch

    let myQueue: dispatch_queue_t = dispatch_queue_create("com.example.queue", nil)
    dispatch_async(myQueue, { () -> Void in
        // Execute some code
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download