nsrunloop

iphone cocoa use of nsrunloop

I find myself using a combination of global vars and nsrunloop to force synchronization throughout my application. Although it works it seems a bit ugly to me. Is there any other way of achieving the same result? Here's a typically example: ParkingSpots *parkingSpots = [[[ParkingSpots alloc] initWithMapViewController:self] autorele...

how to use NSRunLoop in objective-C ?

Hi all, how to use how to use NSRunLoop in objective-C and wait for some variable to change value ? Thanks ...

How can I exit [NSRunLoop runUntilDate]?

Hi everyone, I am writing an application which has to communicate with a device connected via USB. The app sends and receives data in turns from the device on a fixed timing. All Rx/Tx happens in a separate thread because otherwise the UI would be blocked. The basic structure looks basically like this. (autorelease pools and stuff omitt...

iPhone - array lost between appDidBecomeActive: and run loop starting?

EDIT: I stuck in a single call to manually retain the array right after initializing it, and that fixed it. Dur. Thanks. I keep an NSMutableArray in a UIScrollView subclass, and I add to it instances of a UIImageView subclass as each is added as a subview. It needs to be a mutable array, as I plan to rearrange their order in the array e...

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 main() { library_init(); // game init code here while(we_have_not_quit_the_game) { ...

OS X: how to watch socket read events with NSRunLoop?

I'm writing a Cocoa app. There is a socket in the application, and whenever the socket becomes readable I want to read data from the socket, process the data, and update the user interface accordingly. I want to integrate the read event check in the main loop, i.e. I want to attach the socket to the main loop and have the main loop call ...

NSThread, AsyncSocket and object deallocation

Hi! I have a piece of network code that uses AsyncSocket but moves it to a separate runloop. I'm creating this runloop with the following piece of code: [NSThread detachNewThreadSelector:@selector(_workerLoop) toTarget:self withObject:nil]; and here's how my _workerLoop looks like (they're both in the same class): -(void)_workerLoop...

Problem with CFRunLoopRun();

Hello, I have a problem I created this client connects to a server and then want to send and receive strings (this is not implemented yet). When creating the connection I have a problem since the creation of the connection does not do "CFRunLoopRun ();"( tested by degbug). Someone any idea? Thank you. - (void) acceptConnection:(int)fd {...

how can i Iphone EAAccessory callback speed modify?

i'am test my bluetooth device connectting and data read. but data read callback time is very slow. callback Interval time 100ms.. how can i read callback time fastest? - (void)openSessionForProtocol { NSString *protocolString = @"com.company.datapath"; NSArray *accessories = [[EAAccessoryManager sharedAccessoryManager] connectedAc...

How do I start up an NSRunLoop, and ensure that it has an NSAutoreleasePool that gets emptied?

I have a "sync" task that relies on several "sub-tasks", which include asynchronous network operations, but which all require access to a single NSManagedObjectContext. Due to the threading requirements of NSManagedObjectContexts, I need every one of these sub-tasks to execute on the same thread. Due to the amount of processing being don...

When setting up a timed execution using NSDate, NSTimer, and NSRunLoop, which one do I need to not release before the action in complete?

Here's the part of the code dealing with it: NSDate *fireDate = [NSDate dateWithTimeIntervalSinceNow:1.0+index]; NSTimer *timer = [[NSTimer alloc] initWithFireDate:fireDate interval:0.5 target:self ...

How can I do something when a runloop event is done processing?

I have some processing in my Cocoa app that sometimes ends up calling through a hierarchy of data to do a bunch of work as the result of an event. Each small piece creates and destroys some resources. I don't want those resources around most of the time, but I would like to find a smart way of creating them before all the work and killin...

Running and managing NSTimer in different NSThread/NSRunLoop

I'm writing a Cocoa application, with a GUI designed in Interface Builder. I need to schedule background activity (at regular intervals) without blocking the UI, so I run it in a separate thread, like this: - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { [self performSelectorInBackground:@selector(schedule) w...

NSTimer and updating UI

Hi all, Ive been trying to get my game to work correctly with an NSTimer. Ive seen many people have had a similar problem to me and I just need a bit of clarification on something. Basically I have an NSTimer running on the main thread which is updating images which represent the time, but I also have a mapView. When the user pans the ...

how to stop a timer triggered runloop ?

if i set up a runloop like that: NSRunloop* loop = [NSRunloop currentRunLoop]; [runLoop addTimer:anyTimer forMode:NSDefaultRunLoopMode]; can i stop it again ? or is the only way to ignore the notification i use to trigger the further action ? ok, i give an example for the problem: -(void)blinkeffekt:(double)pollingTime{ NSRunLoop* ...

Cocoa Run Loop Input Sources

I am writing an iPhone application, and I need to download files in the background. I can handle the download files part, but I am not so sure about the background part. My current idea is to use a run loop to wait until the user selects a file to download. This appears to work, but a run loop exits if no input source is set. However...

How to wrap an asynchronous class to make it synchronous? Use NSRunLoop?

I'm currently working on an iPhone app and I have a library from a third-party that has asynchronous behavior but that I'd like to wrap with my own class and make it appear synchronous. The central class in this library, let's call it the Connection class, has several functions that have their ultimate result resolved when methods on ...

How do I prioritize performSelectorOnMainThread against NSConnection messages?

I have a lot of NSURLConnections downloading. They may not happen on the main thread. When some of them finish, I call performSelectorOnMainThread for a separate singleton object. I've used both forms of performSelectorOnMainThread, specifying the run loop mode (NSDefaultRunLoopMode) and not specifying it. NSDefaultRunLoopMode is sup...

Error at NSRunLoop after returning from thread method with NSAutoreleasePool

I am getting an EXC_BAD_ACCESS error after I return from a thread method in which I have set up an NSAutoreleasePool. The place of failure is at a call to NSRunLoop. I am trying to wrap a 3rd party library consisting mainly of a class (let's call it the Connection class) and its delegate such that it will behave synchronously instead o...

scheduling async downloads in main thread's runloop vs bg thread's runloop on iOS?

Here's a slide from WWDC 2010 session 208: conn = [[NSURLConnection alloc] initWithRequest:req delegate:self startImmediately:NO]; [conn scheduleInRunLoop: [NSRunLoop currentRunLoop] forMode: NSDefaultRunLoopMode]; [conn start]; Are there any problems associated with putting multiple conn's in the currentRunLoop? What benefits do...