nsrunloop

Is calling -[NSRunLoop runUntilDate:] a good idea?

强颜欢笑 提交于 2019-11-29 04:04:55
Is it generally a good idea to call -[NSRunLoop runUntilDate:] ? It seems to work without any issues, but it makes me nervous to tell the run loop to run from within the run loop. More info: I have a project right now that is fetching data from a REST service. One critical piece of information that needs to be obtained is the range of dates with valid data. It's a very small bit of data that only needs to be gotten once, so I decided that the best way to handle it is to have the property download the data if the local variable is nil . I'm using ASIHTTPRequest and an ASINetworkQueue , so

CFRunLoopRun() vs [NSRunLoop run]

那年仲夏 提交于 2019-11-29 01:27:41
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]) , the loop won't stop. If I start the loop using CRunLoopRun() instead, it works. I have also made sure that the call is made on the correct thread (the one running my custom run loop). I have debugged this with pthread_self() . I found a mailing list archive, where a developer said "don't bother using CRunLoopStop() if you started the loop using

NSTimer requiring me to add it to a runloop

跟風遠走 提交于 2019-11-29 00:56:52
问题 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 it to fire. Below is an example of my question: #define queue dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) #define mainqueue dispatch_get_main_queue() - (void)someMethodBeginCalled { dispatch_async(queue, ^{ int x = 0; dispatch

Order of operations in runloop on iOS

落花浮王杯 提交于 2019-11-28 19:00:26
What is the order of operations on iOS? I'm thinking sepcifically about timing of setNeedsLayout and layoutSubviews setNeedsDisplay and drawRect touch recognition [NSTimer scheduledTimerWithTimeInterval:0.000001 tar(...)] dispatch_async(dispatch_get_main_queue(), ^{ /* code */} As an example of an answer I would like to receive it could be in this format: dispatch_async on main Happens before the next runcycle drawRect Happens at the end of the runcycle rob mayoff (Parts of this are copied from my answer to a similar question .) It turns out that the run loop is complicated, and a simple

Keep NSThread alive and run NSRunLoop on it

瘦欲@ 提交于 2019-11-28 18:45:57
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 calls and subsequently call them until there is nothing left to call. So I need this kind of functionality, an idle thread ready for work that I just can call upon it. My current code looks like this: - (void)doInitialize { mThread = [[NSThread alloc] initWithTarget:self selector:@selector(runThread) object:nil]; [mthread start]; } - (void)runThread {

NSURLConnection needs a NSRunLoop to execute?

有些话、适合烂在心里 提交于 2019-11-28 06:16:57
问题 I'm trying to fetch the contents of a URL from a method called connect. It reads its configuration settings and attempts to fetch the URL. It appears to need the run loop to execute. I though it would just execute once and be done. It seems that I don't need to have that run loop running for any reason other than to fetch this URL once, whenever connect is called. Is there a better way do do this? - (BOOL) connect { // read serverName and eventId from preferences NSMutableArray* preferences;

Run repeating NSTimer with GCD?

别说谁变了你拦得住时间么 提交于 2019-11-27 18:35:11
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) userInfo:nil repeats:YES]; } -(void)runTimer{ NSLog(@"hi"); } But this doesent work: dispatch_queue_t myQueue; -(void)viewDidLoad{ [super viewDidLoad]; myQueue = dispatch_queue_create("someDescription", NULL); dispatch_async(myQueue, ^{ [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(runTimer) userInfo:nil repeats:YES]; }); } -(void)runTimer

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

别等时光非礼了梦想. 提交于 2019-11-27 10:16:46
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 executing. I know the following doesn't work because it gets interleaved with the main run loop so my code might execute on the next run loop but it might not. dispatch_async(dispatch_get_main_queue(),^{ //my code }); The following I believe suffers the same problem as above: dispatch_after(DISPATCH_TIME_NOW, dispatch_get_main_queue(), ^(void){ /

NSTimer not firing when NSMenu is open in Swift

点点圈 提交于 2019-11-27 09:07:04
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, repeats:false) Its selector function sets a mode flag, and calls the original function that set the alarm with new minutes and seconds constants, and also sends a user notification that the session has restarted. I have a menu item that gets updated with the remaining time So I've been opening it to check that my alarm does indeed restart, and that the notification shows once it hits

How do I create a NSTimer on a background thread?

試著忘記壹切 提交于 2019-11-26 21:22:37
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 NSBlockOperation to dispatch a background thread, but I'm wondering if there is a more efficient way of doing this. The timer would need to be installed into a run loop operating on an already-running background thread. That thread would have to continue to run the run loop to have the timer actually fire. And for that background thread to continue being