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

App stops receiving data from socket when UI scroll

I have an iPad app that receives data using UDP sockets. And it has a UIWebView to browse webpages. But while doing scroll in the UIWebView, everything freezes and no data is received. I've been searching and it has something to do with runloops and…
3
votes
1 answer

Adding Pinch/Zoom effect to a UIImageView inside a UIScrollView

I have a very basic screen sharing iPhone app, I have successfully added the pinch/zoom effect to my app using a UIImageView inside a UIScrollView. The UIImageView receives the screen content from the PC on a regular interval. Everything works fine…
Nasreddine
  • 36,610
  • 17
  • 75
  • 94
3
votes
1 answer

In Apple's Foundation/Swift/Objective-C, how does runLoop.run block, but still allow DispatchWorkItems to process?

Why does this code execute like this? Note the comments in the test code which indicate which lines pass and fail. More specifically, how is it that RunLoop.current.run(until: Date(timeIntervalSinceNow: 0.01)) waits there, while still allowing for…
abc123
  • 8,043
  • 7
  • 49
  • 80
3
votes
2 answers

NSRunLoop and GCD queues

I am creating a c++ library for use on iOS (yes, unfortunately it has to be C++) which uses AVCaptureSession to capture video frames, which are delivered via the captureOutput callback. The C++ library is my deliverable product. I have a cocoa touch…
3
votes
2 answers

Add observer to runloop creates retain cycle

let observer = CFRunLoopObserverCreateWithHandler(kCFAllocatorDefault, CFRunLoopActivity.BeforeWaiting.rawValue, false, 0, { (observer, activity) in self.doSomething() }) CFRunLoopAddObserver(CFRunLoopGetCurrent(), observer,…
itenyh
  • 1,921
  • 2
  • 23
  • 38
3
votes
1 answer

Does [NSStream scheduleInRunLoop: forMode:] retain the NSStream?

I want to send and receive some data using nsstreams. I don't want to clutter my code so much, so I was wondering: Do I need to keep a strong reference to a NSStream or is [NSStream scheduleInRunLoop: forMode:] creating a strong reference to it? I…
Jakob
  • 1,126
  • 3
  • 16
  • 38
3
votes
2 answers

How do I use an NSRunLoop on an NSOperationQueue?

I have an app which communicates with an ExternalAccessory over Bluetooth, there is some delay in responses so I want the IO to happen on a background thread. I setup an NSOperationQueue for single-threaded operation to enqueue my…
alfwatt
  • 2,010
  • 2
  • 18
  • 29
3
votes
2 answers

dispatch_async block on main queue is not executed in a modal run loop

I have the following code that checks the RunLoop in an outerloop and then dispatches to the main_thread in an inner loop using dispatch_after. I have two cases where this is called, once when a button is pressed on the nav bar, and the other case…
nishant
  • 736
  • 1
  • 12
  • 22
3
votes
1 answer

NSRunLoop : Is it really idle between kCFRunLoopBeforeWaiting & kCFRunLoopAfterWaiting?

I'm interested about NSRunLoop cycle, especially for main runloop.Via CFRunLoopObserverRef, we can know more about it : CFRunLoopObserverRef observerRef = CFRunLoopObserverCreateWithHandler(NULL, kCFRunLoopAllActivities, YES, 0,…
Jason Lee
  • 3,200
  • 1
  • 34
  • 71
3
votes
1 answer

Why do I need an NSRunLoop to run a timer?

I bought the Big Nerd Ranch Guide for Objective-C, and there is something about NSRunLoop I can't figure out. Here's a chunk of code from the book: NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:2.0 …
ocampeau
  • 157
  • 1
  • 8
3
votes
4 answers

Long-running task in application:didFinishLaunchesWithOptions:

I have some long-running startup tasks (like loading Parse objects from local data storage) in my app. Those tasks should be finished before the interface starts to appear. The app was originally created using storyboards, so the interface starts to…
3
votes
1 answer

Scheduling stream on NSRunLoop

I have been following this tutorial http://www.raywenderlich.com/3932/networking-tutorial-for-ios-how-to-create-a-socket-based-iphone-app-and-server and I got everything working ok, but there is one line in text that I don't understand: Our streams…
MegaManX
  • 8,766
  • 12
  • 51
  • 83
3
votes
0 answers

OS X: capture events when NSApplication is *not* active

How can an app capture events when it is not active? I'm finding that NSApplication doesn't dispatch events unless it's the currently active application (for instance, using nextEventMatchingMask:untilDate:inMode:dequeue:) However, it must be…
Steveo
  • 2,238
  • 1
  • 21
  • 34
3
votes
2 answers

Stop a NSRunLoop in global queue

I have just created a background task with a timer using NSRunLoop and NSTimer in my ViewController: - (void)runBackgroundTask: (int) time{ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ NSTimer* t =…
3
votes
0 answers

iOS Unit testing - bad access error when using NSRunLoop and AFNetworking at the same time

I'm using the code below to test asynchronous calls using AFNetworking in my unit tests for iOS7. When I run the test alone, or even the entire test case, the code works fine. However, when I run the entire test suite, I get EXC_BAD_ACCESS (code=1,…
Alex Stone
  • 46,408
  • 55
  • 231
  • 407