I am very new to Xcode and Objective-C, so I don't really know what I am doing yet! ;-)
Basically I want to have an IPhone Application that can run possibly two threads, which will later use UDP Sockets
to communicate with other Apps.
I have put functions to react when the start-Thread/stop-Thread
Button in the UI are pressed, now I want to fill them with code to actually create and start the threads.
What would be the correct procedure here?
Do I need to subclass NSThread
?
Where do I implement the code, that the new threads will execute?
I can't see a run method, or something similar. I suppose that has something to do with the selector
, which I don't understand.
Use dispatch queues. They're essentially lightweight threads for which you don't need to worry about the threading or queueing directly.
-(void) spawn
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
[self doWorkInBackground];
});
}
You can use one of the built-in queues or your own.
And you should probably read up on blocks too, in particular the memory management aspect.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With