nsthread

How do I create an NSThread that isn't the main thread without performing a selector immediately

萝らか妹 提交于 2019-12-23 10:14:28
问题 I want to create a worker thread that isn't the main thread so I can call ... [self performSelector:@selector(doStuff) OnThread:self.myWorkerThread withObject:nil]; ... in a bunch of locations in my code. How do I create a thread.. any thread and assign it to a variable so I can use it over and over in my code. NSThread detachNewThreadWithSElector will only create one for the purpose of running that one selector. I need to create a thread and use it somehow. I am using iOS and need to perform

Wait for download task to finish in NSURLSession

孤街醉人 提交于 2019-12-23 07:26:27
问题 My scenario looks like this: I have a class which has a function in it and this function makes a POST request to a server with NSURLSession. In another function which is not in that class I call that function with the task in it, which runs asynchronously I think. I'm encountering following problem: When I download the JSON response from the server and write it to a variable and return it, the variable I've written to is still nil since it didn't wait for the thread/task to finish downloading

Deadlocks: How do you determine if a call may cause unsafe painting off of the main thread for iOS?

[亡魂溺海] 提交于 2019-12-23 02:54:25
问题 Drawing/painting should always be done on the GUI thread otherwise deadlocks can occur!... How do you determine if a call may cause unsafe painting off of the main thread for iOS? The problem is we get stacks like this which are not on the main thread... #19 0x02a788d2 in -[CALayer drawInContext:] #20 0x02a784b0 in backing_callback #21 0x02a77d52 in CABackingStoreUpdate #22 0x02a7701d in -[CALayer _display] #23 0x02a76ac7 in CALayerDisplayIfNeeded #24 0x02a689e1 in CA::Context::commit

pass block as parameter in my case

依然范特西╮ 提交于 2019-12-22 01:48:26
问题 I have a function which takes a block as parameter: typedef void (^ MyBlock)(int); -(void)doTask:(MyBlock)theBlock{ ... } I need to run above function on another thread, I want to use - performSelector:onThread:withObject:waitUntilDone: , my current code: NSThread *workerThread = [[NSThread alloc] init]; [workerThread start]; [self performSelector:@selector(doTask:) onThread:workerThread withObject:??? waitUntilDone:NO]; BUT, How can I pass MyBlock parameter with this approach? (Please don't

Objective-C - Canceling a thread?

久未见 提交于 2019-12-21 22:46:15
问题 I have a search function in my app where the user types in the textField, and as the text changes I am searching the local database and populating data in a table. The search might take anywhere between 1 to 10 seconds depending on the text entered, so I decided to use a thread. Every time the text changes I want to cancel the thread (If running already), and start it again with the new keyword. The problem is that according to the documentation calling cancel doesn't guaranty that the thread

Delaying Code Execution on OSX 10.10

馋奶兔 提交于 2019-12-21 06:16:13
问题 I've encountered a very strange issue that affects my code running only on OSX 10.10 systems. I've seen this anomaly occur on over 25 OSX 10.10 systems running my code, whereas the exact same code did not exhibit this behavior before upgrading (10.7). Furthermore, this issue is not 100% reproducible in that it occurs randomly ~0-5% of the time. While testing the code, nothing else critical or CPU exhaustive is occurring on the machine. Even if something else was happening, the very fact that

call a function using thread in xcode

霸气de小男生 提交于 2019-12-21 02:02:34
问题 i have created a thread in xcode and i have given the function name to be called from that thread. but my problem is that the function name which is given to call is not being called(came to know when put a breakpoint in that function) code: NSThread* myThread; [myThread start]; [self performSelector:@selector(func1:) onThread:myThread withObject:nil waitUntilDone:false] and later i tried this one also: NSThread* myThread = [[NSThread alloc] initWithTarget:self selector:@selector(func1:

iPhone: unrecognized selector error

北城余情 提交于 2019-12-20 05:53:26
问题 I'm threeaing some tasks like this : RootViewController - (void)viewDidLoad { [NSThread detachNewThreadSelector:@selector(findSomething) toTarget:self withObject:nil]; } - (void) findSomething { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; doMoreThings [pool release]; } - (void) doMoreThings { doMoreMoreMoreThings on different objects } - (void) foundSomething:(NSFoundThing*)foundObj { do your stuff } oneObject - (void) doMoreMoreMoreThings { do things [self

getting the object passed to the NSThread selector

为君一笑 提交于 2019-12-19 04:57:20
问题 When I'm creating an NSThread I pass it a number that I want the process to be aware of. I can understand how to set the number but I cannot figure out how to read the number from the thread selector method so that I can then pass it to a timer. How do you do it? -(void) setthread { //passing the number to the selector here fine NSThread* timerThread = [[NSThread alloc] initWithTarget:self selector:@selector(startTimerThread) object:[NSNumber numberWithInt:index]];/ [timerThread

Xcode: How to set CA_DEBUG_TRANSACTIONS=1?

南笙酒味 提交于 2019-12-18 14:46:09
问题 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 CATransaction so I can make sure it is running on the main thread. My code doesn't call CATransaction directly. I.e. a search of my code for CATransaction turns up nothing. In Xcode 5, what is the correct way to set CA_DEBUG_TRANSACTIONS=1 in the