Questions tagged [nsrunloop]

NSRunLoop is a class in Apple's Foundation framework. It processes inputs such as user events, network activity, and NSTimer events.

NSRunLoop is a class in Apple's Foundation framework for OS X and iOS. It processes inputs such as user events, network activity, and NSTimer events. Each NSThread object automatically receives its own NSRunLoop; apps cannot explicitly create or manage NSRunLoop objects.

353 questions
5
votes
1 answer

What does "[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]" do?

I have some problem about NSRunLoop. When run the code as below,the main thread seem to stop and It wouldn't run the code after the while loop. I want to know when [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate…
Slemon
  • 791
  • 7
  • 12
5
votes
1 answer

Inter-thread communication in Swift?

My goal is to parse a large XML file (20 GB) with Swift. There are some performance issues with NSXMLParser and bridging to Swift objects, so I'm looking at multi-threading. Specifically the following division: Main thread - parses data Worker…
Bouke
  • 11,768
  • 7
  • 68
  • 102
5
votes
1 answer

NSRunLoop runMode does not always process dispatch_async

I'm trying to get a better understanding of queues and how they work. This snippet is to test their behaviour: - (void)dispatchQueueTest { NSLog( @"Begin test on %@ thread", [NSThread isMainThread] ? @"main" : @"other" ); …
5
votes
1 answer

how to prevent an NSTimer to be delayed or interrupted by user interface actions in iOS 5

How can I prevent a NSTimer from being delayed by the user scrolling a table? I found the answer: I had a timer that repeated about 8 or 9 times with intervals of 0.4 to 0.8 seconds. I don't need much precision, but if the user scrolls a table the…
alvira
  • 67
  • 4
4
votes
1 answer

How to make NSRunLoop work inside a separate thread?

Please look at this code: @interface myObject:NSObject -(void)function:(id)param; @end @implementation myObject -(void)function:(id)param { NSLog(@"BEFORE"); [[NSRunLoop currentRunLoop] runUntilDate:[NSDate…
Andrey Chernukha
  • 21,488
  • 17
  • 97
  • 161
4
votes
1 answer

Difference in usage of function sleep() and [[NSRunLoop currentRunLoop] runUntilDate]

Please consider the following pieces of code: In the first one i call a function which creates an animation. i do that with a certain time interval: start:; [self animationMethod]; [[NSRunLoop currentRunLoop] runUntilDate:[NSDate…
Andrey Chernukha
  • 21,488
  • 17
  • 97
  • 161
4
votes
2 answers

iOS UIScrollView gets stuck and unresponsive with NSRunLoopCommonModes

In my iPhone app I'm using a 3rd party library (libPusher) for WebSockets networking and this library causes every UIScrollView component in my app to become unresponsive. This includes UIScrollViews and UITableView. What happens is that if a user…
Ran
  • 7,541
  • 12
  • 59
  • 72
4
votes
2 answers

How does setNeedsLayout work?

I would like to know how Apple's -setNeedsLayout works. I already know that it's more efficient than directly calling -layoutSubviews, since I might need to do that twice in a method. And that's just what I need it for: some custom…
Christian Schnorr
  • 10,768
  • 8
  • 48
  • 83
4
votes
1 answer

Stop an NSRunLoop from a timer

I've made a RunLoop with a timer that updates a label that displays a countdown. I need the RunLoop to stop once the countdown reaches zero, for the case where the the timer finishes normally I could just use runUntilDate, with the date being the…
Elbimio
  • 1,041
  • 2
  • 10
  • 25
4
votes
3 answers

Background thread NSRunloop run does not exit after NSTimer is invalidated! Why?

I'm creating an NSTimer and adding it to the runloop of a background thread. My code is like the background thread example for this answer: iPhone-SDK:Call a function in the background? After creating the timer and attching it to the runloop from…
Cal
  • 1,625
  • 4
  • 20
  • 30
4
votes
2 answers

Async NSURLConnection, Concurrent NSOperation, when to use NSRunLoop?

I'm trying to run NSURLConnection async in a secondary thread (target is iOS4), for this I have created a concurrent NSOperation, I think I'm almost there, but am not clear on the following: 1) in iOS4 NSOperationQueue addOperation starts the…
cin
  • 131
  • 1
  • 6
4
votes
0 answers

Put run-loop-based NSThread to sleep for an indeterminate amount of time

I have a dedicated networking thread in my iOS app. The thread's -main method looks like this: - (void)main { @try { while (!self.isCancelled) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]…
LinenIsGreat
  • 594
  • 4
  • 13
4
votes
3 answers

Are aysnchronous NSURLConnections multi-threaded

I've noticed that if I create an NSURLConnection and fire the request, all is well. My delegate methods get called and the last delegate method get's called well after the code block invoking the connection completes. Great. That leads me to believe…
Luther Baker
  • 7,236
  • 13
  • 46
  • 64
4
votes
1 answer

Why the call method to runloop.run in the Mac OS console application creates additional threads?

I make experiment with RunLoop. I was create simple Mac OS console application and call only one line of code. RunLoop.current.run() After that in Debug navigator appearance second thread. Why?
Citrael
  • 542
  • 4
  • 17
4
votes
1 answer

Swift 3 Linux with Perfect: Add a scheduled timer with interval to the runLoop

I'm trying to make an application in Swift on my Ubuntu (Ubuntu 15.10 wily, Swift swift-3.0.1-RELEASE) using the Perfect library. I would like to have a function called every X second. For that, I'm using the Timer class of the Foundation…
Aurelien Maigret
  • 402
  • 3
  • 12