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

NSDefaultRunLoopMode vs NSRunLoopCommonModes

Whenever I try to download a big file behind UIScrollView, MPMapView or something, the downloading process gets halted as soon as I touch iPhone screen. Thankfully, an awesome blog post by Jörn suggests an alternative option, using…
Stkim1
  • 1,365
  • 2
  • 9
  • 10
123
votes
6 answers

Understanding NSRunLoop

Can anyone explain for what is NSRunLoop? so as I know NSRunLoop is a something connected with NSThread right? So assume I create a Thread like NSThread* th=[[NSThread alloc] initWithTarget:self selector:@selector(someMethod) object:nil]; [th…
taffarel
  • 4,015
  • 4
  • 33
  • 61
76
votes
10 answers

How do I create a NSTimer on a background thread?

I have a task that needs to be performed every 1 second. Currently I have an NSTimer firing repeatedly every 1 sec. How do I have the timer fire in a background thread (non UI-thread)? I could have the NSTimer fire on the main thread then use…
AWF4vk
  • 5,810
  • 3
  • 37
  • 70
53
votes
5 answers

RunLoop vs DispatchQueue as Scheduler

When using new Combine framework you can specify the scheduler on which to receive elements from the publisher. Is there a big difference between RunLoop.main and DispatchQueue.main in this case when assigning publisher to UI element? The first one…
mikro098
  • 2,173
  • 2
  • 32
  • 48
48
votes
5 answers

How do you schedule a block to run on the next run loop iteration?

I want to be able to execute a block on the next run loop iteration. It's not so important whether it gets executed at the beginning or the end of the next run loop, just that execution is deferred until all code in the current run loop has finished…
lmirosevic
  • 15,787
  • 13
  • 70
  • 116
34
votes
3 answers

Using NSURLSession from a Swift command line program

I'm trying to test a little proof-of-concept command line app prior to integrating it into a larger app. What I'm trying to do is download some data using NSURLSession using this example. However it appears that if I use the examples given in a…
Friedrich 'Fred' Clausen
  • 3,321
  • 8
  • 39
  • 70
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
23
votes
2 answers

How to "validate" a NSTimer after invalidating it?

So basically, I have this timer that should be repeated when it receives a key event, and invalidates when the user releases the key. However, I am unable to "validate" the timer back even by calling the addTimer:forMode: in NSRunLoop. Does anyone…
TheAmateurProgrammer
  • 9,252
  • 8
  • 52
  • 71
22
votes
6 answers

NSTimer requiring me to add it to a runloop

I am wondering if someone can explain why dispatching back to the main queue and creating a repeating NSTimer I am having to add it to RUN LOOP for it too fire? Even when using performselectorOnMainThread I still have to add it to a RUN LOOP to get…
chicken
  • 1,618
  • 5
  • 24
  • 35
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
3 answers

Run repeating NSTimer with GCD?

I was wondering why when you create a repeating timer in a GCD block it doesen't work? This works fine: -(void)viewDidLoad{ [super viewDidLoad]; [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(runTimer)…
Praxder
  • 2,315
  • 4
  • 32
  • 51
15
votes
1 answer

CFRunLoopRun() vs [NSRunLoop run]

I have an NSRunLoop object, to which I attach timers and streams. It works great. Stopping it is another story alltogether. I run the loop using [runLoop run]. If I try to stop the loop using CRunLoopStop([[NSRunLoop currentRunLoop] getCFRunLoop]),…
Jörgen Sigvardsson
  • 4,839
  • 3
  • 28
  • 51
14
votes
3 answers

How to send selectors or blocks to an NSRunLoop to perform?

I need to guarantee that the same thread performs various actions at arbitrary times. First the thread needs to initialize a library, then I want the thread to sleep until work needs to be done and upon user input, I need to be able to pass…
Ben S
  • 68,394
  • 30
  • 171
  • 212
12
votes
2 answers

NSTimer not firing when NSMenu is open in Swift

I have a timer that runs to restart an alarm once it goes off. alarm = NSTimer.scheduledTimerWithTimeInterval( 60 * minutesConstant + secondsConstant, target:self, selector: Selector("endSession"), userInfo: nil, …
Spencer Wood
  • 610
  • 6
  • 15
12
votes
4 answers

How can I remove UIApplicationMain from an iPhone application?

I'm trying to port a game library over to the iPhone. Unlike SDL, this library doesn't take full control of your main() function, it's communicated with via quickly-returning functions from your own code. So, for example, obvious pseudocode: int…
ZorbaTHut
  • 1,163
  • 1
  • 11
  • 19
1
2 3
23 24