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
156
votes
7 answers

How to check current thread in Swift 3?

How do I check which one is the current thread in Swift 3? In previous versions of Swift it was possible to check if the current thread was the main one by doing this: NSThread.isMainThread()
BalestraPatrick
  • 9,944
  • 4
  • 30
  • 43
91
votes
12 answers

Objective-C find caller of method

Is there a way to determine the line of code a certain method was called from?
ennuikiller
  • 46,381
  • 14
  • 112
  • 137
40
votes
1 answer

Difference in scheduling NSTimer in main thread and background thread?

When I call scheduledTimerWithTimeInterval:target:selector:userInfo:repeats: on the main thread and set time interval to 5 seconds code below timer gets executed, and after 5 seconds timer selector is called. But if I try same in some background…
MegaManX
  • 8,766
  • 12
  • 51
  • 83
36
votes
1 answer

MBProgressHUD blocking user interaction

My application has a MBProgressHUD on the screen while the CLLocationManager is getting the user current location at a separate thread in the background. Sometimes the location process start to take so long and obviously I would like to let the user…
vilelam
  • 804
  • 1
  • 11
  • 19
31
votes
2 answers

need some clarifications about dispatch queue, thread and NSRunLoop

The following things are what I know & understand: Global queue is a concurrent queue which can dispatch tasks to multiple threads. The order of executing task is not guaranteed.…
Leem.fin
  • 40,781
  • 83
  • 202
  • 354
30
votes
2 answers

NSThread vs. NSOperationQueue vs. ??? on the iPhone

Currently I'm using NSThread to cache images in another thread. [NSThread detachNewThreadSelector:@selector(cacheImage:) toTarget:self withObject:image]; Alternately: [self performSelectorInBackground:@selector(cacheImage:)…
kubi
  • 48,104
  • 19
  • 94
  • 118
29
votes
2 answers

dispatch_get_main_queue() in main thread

I have method which makes UI changes in some cases. For example: -(void) myMethod { if(someExpressionIsTrue) { // make some UI changes // ... // show actionSheet for example } } Sometimes myMethod is called from the mainThread…
B.S.
  • 21,660
  • 14
  • 87
  • 109
28
votes
7 answers

NSOperation - Forcing an operation to wait others dynamically

I am trying to implement an operation queue and I have the following scenario: NSOperation A NSOperation B NSOperation C NSOperation D NSOperationQueue queue I start adding A to queue. During the execution of A I need to get some data from B and I…
Rafael
  • 1,655
  • 3
  • 17
  • 25
25
votes
3 answers

Help with multi-threading on iOS?

I have an application which utilizes OpenEars and the Flite library. The problem is that the Flite library is resource intensive and it's freezing up my app. I suspect that running Flite on a background thread will fix things, but I have no idea how…
Moshe
  • 57,511
  • 78
  • 272
  • 425
22
votes
2 answers

Keep NSThread alive and run NSRunLoop on it

So I'm starting a new NSThread that I want to be able to use later by calling performSelector:onThread:.... From how I understand it calling that methods add that call to the runloop on that thread, so on its next iteration it will pop all these…
Erik Rothoff
  • 4,826
  • 9
  • 41
  • 59
22
votes
2 answers

Which is the best of GCD, NSThread or NSOperationQueue?

What's the best way of multithreading in iOS as we have three options GCD, NSThread, and NSOperationQueue? I am confused in which one is the best? If none, then which should be used in what scenario and how they differ and also, if someone has some…
21
votes
2 answers

GCD vs performSelectorInBackground/performSelectorOnMainThread

I am new in ios development. I have following questions: When we use GCD(dispatch_group_async, dispatch_async(dispatch_get_main_queue()...) and when we use performSelectorInBackground/performSelectorOnMainThread? What's the differences between…
YU FENG
  • 888
  • 1
  • 12
  • 29
20
votes
3 answers

Is it ok to create a UIView on a background thread?

I know UIView are not thread safe so i cant add a view on a background thread, to work around this is it ok to create a UIView on a background thread then add it on the main thread? Note: the reason im not doing this on the main thread is because my…
Jason McTaggart
  • 878
  • 1
  • 7
  • 18
19
votes
3 answers

Grand Central Dispatch vs. NSThread

I created some test code for NSThread and Grand Central Dispatch (GCD): - (void)doIt:(NSNumber *)i { sleep(1); NSLog(@"Thread#%i", [i intValue]); } - (IBAction)doWork:(id)sender { for (int i = 0; 10 > i; i++) { NSNumber *t = [NSNumber…
CarlJ
  • 9,461
  • 3
  • 33
  • 47
16
votes
1 answer

Xcode: How to set CA_DEBUG_TRANSACTIONS=1?

I'm getting this warning in the log window of the debugger: CoreAnimation: warning, deleted thread with uncommitted CATransaction; set CA_DEBUG_TRANSACTIONS=1 in environment to log backtraces. I have to find out what code of mine is calling…
VikR
  • 4,818
  • 8
  • 51
  • 96
1
2 3
48 49