Let’s say I have a class and *classMain is an object for this class. Now this class as a instance method – performAction. So normally to run the method, I would do:
[classMain performAction]
Now if i want to use NSOperationQueue to run this, I would do:
NSOperationqueue *opQueue = [[NSOperation alloc] init];
[opQueue addOperation: classMain].
What i want to do is actually add [classMain performAction] to the queue, so I can run the method I want ?
Also is there a better recommend way of running threads ( so my application does not get locked) in 10.7 ?
There are lots of ways to run threads and to run various actions on different threads. You may find this resource helpful:
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Multithreading/CreatingThreads/CreatingThreads.html
And if you just have a simple task that you want to run in the background without locking your app, you may find that the most straightforward solution is to use performSelectorInBackground:withObject:.
As for which approach is recommended, it really depends upon your specific use-case and what sort of work you are offloading to a separate thread.