Questions tagged [nsthread]

`NSThread` is part of the Objective-C Foundation Framework and provides developers a way to create and manage threads.

An instance of NSThread controls a thread of execution. Developers can use this class when they would like to perform a series of tasks in its own thread of execution. An example is if the developer wanted to have an Objective-C method run in its own thread of execution.

Threads are useful for long-running tasks that avoid blocking the main thread of the application (where user interface and event-related tasks are handled), as well as dividing a large task into several smaller sub-tasks. This can lead to performance improvements.

In GNUStep, NSThread essentially encapsulates OpenStep threading. Each process starts with a main thread and additonal threads can be created by using NSThread. The GNUStep implementation of OpenStep was designed so that the internals of the base library do not use threading (except in the case of methods that explicitly deal with threads). This makes it possible to write applications without any sort of threading.

References

729 questions
7
votes
2 answers

How can I fade out an AVAudioPlayer on a background thread?

I have an audio file which needs to fade out while the user is scrolling a UIScrollView. However, any performSelector:withObject:afterDelay: method is blocked until the user has stopped scrolling. So I have tried to create some code to perform a…
jowie
  • 8,028
  • 8
  • 55
  • 94
7
votes
3 answers

Order of operations in runloop on iOS

What is the order of operations on iOS? I'm thinking sepcifically about timing of setNeedsLayout and layoutSubviews setNeedsDisplay and drawRect touch recognition [NSTimer scheduledTimerWithTimeInterval:0.000001…
hfossli
  • 22,616
  • 10
  • 116
  • 130
7
votes
1 answer

performSelector:onThread: in Swift?

In a current iOS app I am using this perform selector approach: [self performSelector:@selector(doSomething) onThread:myThread withObject:nil waitUntilDone:NO modes:[NSArray…
zumzum
  • 17,984
  • 26
  • 111
  • 172
7
votes
2 answers

animateWithDuration: corrupts smooth progressbar increment

In one of my views i need to animate frame property of a UIImageView and while doing it i want to show a progress bar(UIProgressView) in the title view of the navigation bar.The problem is the if i comment out the following animation blocks the…
Ilker Baltaci
  • 11,644
  • 6
  • 63
  • 79
7
votes
4 answers

Risk Assessment: Using Pthreads (vs. GCD or NSThread)

A colleague suggested recently that I use pthreads instead of GCD because it's, "way faster." I don't disagree that it's faster, but what's the risk with pthreads? My feeling is that they will ultimately not be anywhere nearly as idiot-proof as GCD…
Dan Rosenstark
  • 68,471
  • 58
  • 283
  • 421
7
votes
2 answers

Using _cmd to perform method on main thread in objective c

I came across this _cmd trick: -(void)methodToBeRunOnMainThreadWithObj:(id)object { if (![NSThread isMainThread) { [self performSelectorOnMainThread:_cmd withObject:object] } else { // ... method body } } Is this a…
Sean Danzeiser
  • 9,141
  • 12
  • 52
  • 90
7
votes
5 answers

iphone - Should I use NSOperationQueue and NSOperation instead of NSThread?

I am facing a design problem of my app. Basically, the followings are what I am going to do in my app. A single task is like this: Read custom object from the underlying CoreData databse Download a json from a url Parse the json to update the…
Jackson Tale
  • 25,428
  • 34
  • 149
  • 271
7
votes
3 answers

When Would Anyone Want To Use NSThreads over the GCD?

Are there any cases when anyone would want to use raw NSThreads instead of GCD for concurrency? I love the GCD, but I want to know if I will need to use NSThreads for Cocoa/Cocoa-Touch eventually.
Andy Ibanez
  • 12,104
  • 9
  • 65
  • 100
6
votes
2 answers

Objective C & iOS: running a timer? NSTimer/Threads/NSDate/etc

I am working on my first iOS app, and have run in the first snag I have not been able to find a good answer for. The problem: I have a custom UIGestureRecognizer and have it all wired up correctly, and I can run code for each touch in the @selector…
solenoid
  • 954
  • 1
  • 9
  • 20
6
votes
4 answers

How to cancel or stop NSThread?

I'm doing an app that loads the contents of viewControllers using NSThread while is reading an XML file. I have it done as follows: -(void)viewDidAppear:(BOOL)animated { // Some code... [NSThread detachNewThreadSelector:@selector(loadXML)…
karse23
  • 4,055
  • 6
  • 29
  • 33
6
votes
3 answers

Difference between NSThreads, NSOperations and performSelector

I want to ask some simple but important questions regarding iPhone development. If we have to perform tasks in the background and when the background tasks are completed we will update the UI, for this we can use NSThreads, NSOperations or…
Rajender Kumar
  • 1,377
  • 19
  • 32
6
votes
2 answers

NSThread VS pthreads

What is the difference between NSThread and pthread? Does NSThread use pthread as its internal implementation and do we really need the extra overhead of NSThread when pthreads suffice especially on the iPhone.
shreyasva
  • 13,126
  • 25
  • 78
  • 101
6
votes
3 answers

Creating threads with parameters in Swift?

I am trying to create a thread in swift and send two parameters. I create thread and this work: let thread = NSThread(target:self, selector:"getData", object:nil) thread.start() But how to send parameters to my func getData? How to create object…
gellezzz
  • 1,165
  • 2
  • 12
  • 21
6
votes
2 answers

What does NSRunLoop do?

I read many posts about NSRunLoop, like this, this, this. But can't figure out what NSRunLoop actually does What I usually see is a worker thread wthread = [[NSThread alloc] initWithTarget:self selector:@selector(threadProc) object:nil]; [wthread…
onmyway133
  • 45,645
  • 31
  • 257
  • 263
6
votes
2 answers

scheduling a Thread after a Thread in iphone application

I want to schedule a thread after a thread completion. Is it possible ? How? For example ( to specify my need ) - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { // 1. response - schedule myThread // 2.…
sagarkothari
  • 24,520
  • 50
  • 165
  • 235