dispatch-async

dispatch_async without using a block

[亡魂溺海] 提交于 2019-12-24 09:47:20
问题 I want to use dispatch_async to occasionally pull a changing resource from my web server (about every 60 seconds). I want to make use of dispatch_async but I want to give it a function name instead. Since I want that function to sleep and redo the same thing again. This is what I am trying to do dispatch_async(self.downloadQueue, @selector(getDataThread:)); (this does not compile) I think a while loop is not a good idea so I'm wondering what was the best approach for this 回答1: How about

Objective-C freezed GUI also with queue

痞子三分冷 提交于 2019-12-24 04:21:42
问题 I'm trying to understand queue in iOS; with this code dispatch_queue_t coda_thread=dispatch_queue_create("coda_thread",NULL); //UIPROGRESS VIEW for(i=0;i<=10;i=i+1) { dispatch_async(coda_thread, ^{ NSLog(@"CODA_THREAD"); NSLog(@"attendo.."); [NSThread sleepForTimeInterval:10]; dispatch_async(dispatch_get_main_queue(), ^{ NSLog(@"MAIN THREAD"); NSLog(@"aggiorno barra.."); [self.upv setProgress:i/10 animated:YES]; }); }); } I expected no freeze in GUI because sleep is in coda_thread (and not in

swift: async task + completion

删除回忆录丶 提交于 2019-12-22 07:04:59
问题 I got quite a lot of confusion on async tasks in swift. What i want to do is something like this... func buttonPressed(button: UIButton) { // display an "animation" tell the user that it is calculating (do not want to freeze the screen // do some calculations (take very long time) at the background // the calculations result are needed to update the UI } I tried to do something like this: func buttonPressed(button: UIButton) { let queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY

dispatch_async and unexpected non-void return value in void function in Swift

南笙酒味 提交于 2019-12-20 05:16:30
问题 I have a function in my appDelegate that returns user's current location. Now I want to call it asynchronously at some other place and I did: func handleLocation() -> CLLocation { let priority = DISPATCH_QUEUE_PRIORITY_DEFAULT dispatch_async(dispatch_get_global_queue(priority, 0)) { let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate appDelegate.startGPS() while (!appDelegate.isLocationFixed()) { sleep(1) } dispatch_async(dispatch_get_main_queue()) { return

Can we update UI from background Thread?

我与影子孤独终老i 提交于 2019-12-20 04:45:25
问题 Hello iOS experts just to clear my concept I have a bit confusion about UI updation from Main Thread. Apple requirements are that all UI related stuff should be carried out in main Thread.So to test: Case1: I dispatch a task to a global dispatch concurrent queue asynchronously . After some processing I update my UI stuff directly from the concurrent queue (background thread), working fine using the below code. dispatch_queue_t myGlobalQueue; myGlobalQueue = dispatch_get_global_queue(DISPATCH

Swift 2 to 3 Migration dispatch_get_global_queue [duplicate]

五迷三道 提交于 2019-12-18 07:23:56
问题 This question already has answers here : How do I dispatch_sync, dispatch_async, dispatch_after, etc in Swift 3, Swift 4, and beyond? (6 answers) Closed 3 years ago . I have the following code that I've been trying to translate into swift 3 from swift 2. Here is what I have so far. DispatchQueue.async(group: DispatchQueue.global(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),execute: { self.controllerDelegate?.codeToRun(progressWindowViewController: self) }) I am getting an error that says Cannot invoke

Multiple async requests at once in objective c

自闭症网瘾萝莉.ら 提交于 2019-12-17 20:28:51
问题 I have am downloading multiple images from a web server at the same time, and I the problem is they are getting mixed up with each other. dispatch_async(dispatch_get_global_queue(0,0), ^{ NSData * data = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"website.com"]]; if (data == nil) return; dispatch_async(dispatch_get_main_queue(), ^{ cell.imageView.image = [UIImage imageWithData:data]; }); }); I got this code from: Getting Image from URL Objective C. How do i fix this?? also is

Dispatch Queue and global NSMutableDictionary - Objective C

主宰稳场 提交于 2019-12-14 03:30:09
问题 I'm trying to use a global NSMutableDictionary from a dispatch queue. However, the items keep coming back NULL. What I'm trying to do is access an external json file with a dispatch_queue, then populate a UITableView with this info. Here's what I have vc.h: @interface viewcontroller { NSMutableDictionary *jsonArray; } vc.m: #define kBgQueue dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) //1 #define jsonTest [NSURL URLWithString:@"http://www.sometest.com/test.php"] -(void

UILabel won't update even on dispatch_async

て烟熏妆下的殇ゞ 提交于 2019-12-13 08:36:09
问题 Any reason why my label won't update? - (void)setLabel:(NSNotification*)notification { dispatch_async(dispatch_get_main_queue(), ^{ NSLog(@"setLabel"); [self.label setText:@"My Label"]; }); } I've also tried using performSelectorOnMainThread to no avail. Note that setLabel is appears on the log. Additional info: I also have two other functions which does the same thing but only with a different text. The two other functions doesn't have dispatch_async but they both work. Also, the

Waiting for two different REST/Network calls to complete

老子叫甜甜 提交于 2019-12-13 01:54:05
问题 I am making a lot of calls using REST and decided to separate these connection calls into a separate object, to be called from my UI classes. Here is the function I am using, it will not wait for the requests to be complete. I am not sure what I am doing wrong and have tried using many examples off stack and the net, including: Wait until swift for loop with asynchronous network requests finishes executing Waiting until the task finishes //let loader = from Oauth2/p2_OAuth2 pod to load JSON