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
1
vote
0 answers

Cannot post to twitter via Twitter-OAuth-iPhone in a NSThread

I recently started using Ben Gottlieb's Twitter-OAuth-iPhone class to post status updates in app. I have successfully done so, when executed on the application's main thread. But, when I throw it in a "NSThread detachNewThreadSelector" the post…
adamweeks
  • 1,332
  • 2
  • 14
  • 21
1
vote
3 answers

NSThread for UITableView

In the viewDidLoad() method of view controller I am calling [NSThread detachNewThreadSelector:@selector(readFromFaceBook) toTarget:self withObject:nil]; readFromFaceBook will pull the data from…
bp581
  • 859
  • 1
  • 16
  • 47
1
vote
2 answers

What is the iOS thread model?

I have used Java threads and POSIX threads in C before. Recently I am learning iOS. It seems to me that iOS thread model is a bit different. In particular there are runloops associated with threads and you can call methods on particular threads. I…
Ibraheem Moosa
  • 154
  • 1
  • 9
1
vote
1 answer

What is the correct way to synchronize this multithreaded code (iOS/Cocoa)?

Let's say I have an NSMutableArray of objects (NSMutableArray is not thread-safe), and I have these methods on an object that contains this array (this is a simplified example for the sake of clarity): - (void)addObject:(id)object { if…
Chris
  • 556
  • 1
  • 4
  • 18
1
vote
0 answers

iPhone - Problem with NSThread and NSURLConnection

In my iphone application, i'm creating NSThread and running some code. In the same thread, I'm using NSURLConnection and trying to get some data from server. I implemented all the delegates related to connection. In the thread i also had the…
Satyam
  • 15,493
  • 31
  • 131
  • 244
1
vote
4 answers

Display a welcome View with activity indicator while data downloading [iphone sdk]

I have a navigation based Iphone application. Before root view(UITableView) I want to display a WELCOME view with few UILabels and a UIActivityIndicator on it. This WELCOME view will be displayed when the application launch with the activity…
1
vote
3 answers

UI update on NSThread

I create a NSThread to change the text of textField,and i make sure the NSThread is not main thread.Though,the textField'text changed.Shouldn't the UI update must be on the main thread? @interface ViewController () @property (weak, nonatomic)…
1
vote
3 answers

How to not get NSSearchField freezing?

I've got a NSSearchField, whose action method does all the searching stuff, by analyzing the sender argument (string). Now the searching stuff (feeding a large array) is kind of CPU intensive, which lets my search field freeze for some seconds. In…
bijan
  • 1,675
  • 18
  • 30
1
vote
2 answers

How to execute block on thread instance?

I perform URLSession.shared.downloadTask request, but would like to execute code on the same thread the downloadTask was executed on. For example: func sample() { let thread = Thread.current URLSession.shared.downloadTask(with: file) { …
TruMan1
  • 33,665
  • 59
  • 184
  • 335
1
vote
2 answers

CoreAudio and Threads, how to?

can I set up a separate thread for an AU Callback (which is in C)? How ? If so what threads methods is best for CoreAudio? NSThreads? NSOperationQueue? GCD? Something else? Many thanks.
André
  • 671
  • 1
  • 7
  • 21
1
vote
1 answer

NSThread - get bool value

I am trying to get the boolean value that's returned by -(BOOL)backupDropletUpdateAvailable through NSThread. To do this, I've tried the following: ` BOOL isAvailable = NO; [NSThread detachNewThreadSelector:@selector(backupDropletUpdateAvailable)…
Pripyat
  • 2,937
  • 2
  • 35
  • 69
1
vote
1 answer

Image not appearing in detachNewThreadSelector

I am having trouble with my game and was wondering if anyone can help? I am loading an overlay image on the screen when a user clicks on an answer in my quiz game, the image is of either a tick or cross to indicate if the answer was correct. The…
user474582
  • 13
  • 2
1
vote
1 answer

EXC_BAD_ACCESS while [WKInterfaceTable setNumberOfRows:withRowType]

I wanna to update table from a background thread using this part of the code __block typeof(self.tableB) self_tableB = self.tableB; [lwc setBaseControllerCallback:^(int ndx) { __block typeof(ndx) ndx_t = ndx; [[NSOperationQueue…
Vyacheslav
  • 26,359
  • 19
  • 112
  • 194
1
vote
1 answer

initialize & start NSThread with target & selector

I have a function which takes a block as parameter: typedef void (^ MyCallBack)(int); -(void)doTask:(MyCallBack)callback{ ... } I need to run the function in another thread with NSThread: NSThread* myThread = [[NSThread alloc]…
Leem.fin
  • 40,781
  • 83
  • 202
  • 354
1
vote
1 answer

performSelector:onThread:withObject:waitUntilDone: doesn't execute my function

I have a function: -(void)doTask{ NSLog(@"do task start."); ... } I want to run this function on another thread, this is what I tried: NSThread *workerThread = [[NSThread alloc] init]; [workerThread start]; [self…
Leem.fin
  • 40,781
  • 83
  • 202
  • 354