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
1 answer

How did a command line Objective-C program create its main NSThread thread?

I am wondering if the a objective-c program itself is a NSThread object. A very simple example: #import #import int main() { printf("Is this a main thread? %s\n", [NSThread isMainThread] ? "yes" : "no"); …
Jason Umi
  • 31
  • 3
1
vote
1 answer

Threaded NSTimer

I am aware of the many questions regarding this topic, as I myself have asked one previously however, my issue now seems to be more related to the threading part. I have the following 2 methods. -(void) restartTimer { NSAutoreleasePool *pool =…
Jules
  • 660
  • 8
  • 29
1
vote
1 answer

Memory issues with -performSelector:onThread:withObject:waitUntilDone:

Passing an NSDictionary literal as the object to -performSelector:onThread:withObject:waitUntilDone: will cause it to crash as the other thread's run loop's autoreleasepool will attempt to release it. What is the best way to deal with this issue?…
Matoe
  • 2,742
  • 6
  • 33
  • 52
1
vote
0 answers

How can I use UIProgressView to show the NSData write and read in ios?

As title, I want to know the progress of NSData write or read in the iOS device, use the UIProgressView to show it, use NSThread to write data and use NSTimer to check file size, but I have not been successful. How can I do it? -…
Tom
  • 31
  • 5
1
vote
1 answer

How to Loop NSThread?

I am curious to know if you can loop an NSThread for the iphone sdk. I have learned that instead of using NSTimers which do run off of the main UI, I can use NSThreads to run actions in the background. Most of my NSTimers have the "repeats:" to…
lab12
  • 6,400
  • 21
  • 68
  • 106
1
vote
2 answers

NSThread terminating too early

I have an app that uploads to Google Spreadsheets via the GData ObjC client for Mac/iPhone. It works fine as is. I'm trying to get the upload portion on its own thread and I'm attempting to call the upload method on a new…
Daddy
  • 9,045
  • 7
  • 69
  • 98
1
vote
1 answer

XML parsing on new thread

In my application, I want to fetch new xml data after user scrolls through tableview and pulls the first cell down. As the data is loaded in tableview in chronological order, the updated data will be shown before the first cell. I want to run this…
neha
  • 6,327
  • 12
  • 46
  • 78
1
vote
2 answers

Multiple Async calls in iOS

I want to call a web service to upload some image data to the server. I have to send the data 5 times to the server. This piece of code is written in a function which is called after 10 seconds duration by a timer. Now the problem is that the…
1
vote
0 answers

Pass an Object of to an NSThread and keep sending it messages?

All examples/tutorials I can find regarding NSThreads and the only way I have ever dealt with them is using [NSThread detachNewThreadSelector:@selector(processDataMethod) toTarget:self withObject:nil]; to move all processing in a method to another…
RickiG
  • 11,380
  • 13
  • 81
  • 120
1
vote
1 answer

iOS: dispatch_block_t execute some part of code two times and I dont know why

When I call the following function: + (void) myMethod:(NSString *) myConstString array: (NSArray *) myArray { dispatch_block_t block = ^{ for (int i = 0; i < myArray.count; i++) { if ([@"myString1" isEqual:…
Trzy Gracje
  • 2,969
  • 4
  • 20
  • 24
1
vote
1 answer

Keep a reference to an NSThread around and message its objects?

I am a bit uncertain on how to do this: I start a "worker-thread" that runs for the duration of my apps "life". [NSThread detachNewThreadSelector:@selector(updateModel) toTarget:self withObject:nil]; then - (void) updateModel { …
RickiG
  • 11,380
  • 13
  • 81
  • 120
1
vote
2 answers

NSThread and memory management

Imagine I create and execute an NSThread object using detachNewThreadSelector:toTarget:withObject:. The method executed by the thread might look like this: - (void)search { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; //…
misfit153
  • 11
  • 1
1
vote
1 answer

Difference between NSThread and detachNewThreadSelector:toTarget:withObject:

In the NSThread documentation, I came across the method detachNewThreadSelector:toTarget:withObject:. What's the difference between that method and creating a thread with initWithTarget:selector:object: and then starting it with start?
ryyst
  • 9,563
  • 18
  • 70
  • 97
1
vote
1 answer

tableView still shows two rows even though I deleted one from the data source and reloaded the table

I have an NSMutableArray _conversationsArray that basically stores IDs of all the conversations a user has in my app. Based on that value I show different number of rows in the tableView. When I delete a conversation from the data source and trigger…
budiDino
  • 13,044
  • 8
  • 95
  • 91
1
vote
1 answer

NSThread shared object issue

I'm getting an “EXC_BAD_ACCESS” but just can't work out why, any help would be massive - thank you in advance. The user takes a picture and I want to do some processing on it in another thread... -…
Chris
  • 2,727
  • 2
  • 27
  • 28