grand-central-dispatch

how to check an dispatch_async block has finished running

夙愿已清 提交于 2020-01-01 05:13:07
问题 So basically I need to be able to run a segue after a block has finished running. I have a block which does some JSON stuff and I need to know when that has finished running. I have a queue which I have called json_queue. jsonQueue = dispatch_queue_create("com.jaboston.jsonQueue", NULL); I then have a dispatch_async block with this syntax: dispatch_async(jsonQueue, ^{ [self doSomeJSON]; [self performSegueWithIdentifier:@"modaltomenu" sender:self]; }); It wont let me perform the line: "[self

Dispatched Saving operations on applicationDidEnterBackground:

跟風遠走 提交于 2020-01-01 00:36:10
问题 Apple's documentation of "App States and Multitasking" (Section "What to Do When Moving to the Background") say for saving when the app goes to background: Save user data and app state information. All unsaved changes should be written to disk when entering the background. This step is necessary because your app might be quietly killed while in the background for any number of reasons. You can perform this operation from a background thread as needed. When I start a dispatched operation e.g.

Difference between DispatchSourceTimer, Timer and asyncAfter?

耗尽温柔 提交于 2019-12-31 09:13:07
问题 I am struggling to understand the key differences between DispatchSourceTimer, Timer and asyncAfter ( in my case for scheduling a task that needs to be ran every X seconds, although understanding the differences in timers can be useful to ) (Or is there another (more efficient) scheduling mechanism in Swift besides the listed timers?). A Timer needs an active run loop on the current queue it was started on. A DispatchSourceTimer does not need that. A Timer keeps the CPU from going into the

iOS GCD: Difference between any global queue and the one with background priority (DISPATCH_QUEUE_PRIORITY_BACKGROUND)?

筅森魡賤 提交于 2019-12-31 08:55:08
问题 I am reading Concurrency Programming Guide and things confuse me. I see a lot of code invoking the following for any background task: dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); Now what I mean by 'background' is the popular meaning: Something that gets executed anywhere other than the main (UI) thread So following the docs, the above statement returns any non-main-thread queue with differing priorities. My question is - why does then DISPATCH_QUEUE_PRIORITY_BACKGROUND

Why weird behavior of concurrent queue?

痴心易碎 提交于 2019-12-31 03:17:06
问题 I am trying to understanding the concurrent queue of iOS GCD. The I made some code to test it, but found something weird. code as below: _syncQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0); for (int index = 0; index < 3; ++index) { dispatch_sync(_syncQueue, ^{ NSLog(@"sync@@@@@@ >>>> %d ",index); sleep(1); NSLog(@"sync@@@@@@ <<<< %d ",index); }); } for (int index = 3; index < 6; ++index) { dispatch_async(_syncQueue, ^{ NSLog(@"sync===== >>>> %d ",index); sleep(1); NSLog(@

EXC_BAD_INSTRUCTION happens when using dispatch_get_global_queue on ios 7(swift)

僤鯓⒐⒋嵵緔 提交于 2019-12-30 18:33:21
问题 let downloadGroup = dispatch_group_create() var images = [UIImage]() var errors = [NSError]() dispatch_apply(UInt(urls.count), dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0)) { (i) in dispatch_group_enter(downloadGroup) SimpleCache.sharedInstance.getImage(urls[Int(i)], completion: { (image, error) -> () in if let fullImage = image { images.append(fullImage) } else { if let err = error { DLog(err.description) errors.append(err) } } dispatch_group_leave(downloadGroup); }) } dispatch

How to draw to GLKit's OpenGL ES context asynchronously from a Grand Central Dispatch Queue on iOS

ぃ、小莉子 提交于 2019-12-30 09:53:22
问题 I'm trying to move lengthy OpenGL draw operations into a GCD queue so I can get other stuff done while the GPU grinds along. I would much rather prefer to do this with GCD vs. adding real threading to my app. Literally all I want to do is be able to Not block on a glDrawArrays() call so the rest of the UI can stay responsive when GL rendering gets very slow. Drop glDrawArrays() calls when we aren't finishing them anyway (don't build up a queue of frames that just grows and grows) On Apple's

Is DispatchQueue.global(qos: .userInteractive).async same as DispatchQueue.main.async

Deadly 提交于 2019-12-30 07:51:25
问题 I was going through the tutorial : https://www.raywenderlich.com/148513/grand-central-dispatch-tutorial-swift-3-part-1 And came across the definition of QoS class User-interactive . Its mentioned there that this should run on main thread. So, my question is then what is the difference between the DispatchQueue.global(qos: .userInteractive).async{} and DispatchQueue.main.async{} Thanks!! 回答1: The "quality of service" definitions are described here: https://developer.apple.com/library/content

Displaying UIAlertView after some time

旧时模样 提交于 2019-12-30 07:23:47
问题 I'm trying to display a UIAlertView after some time (like 5 minutes after doing something in the app). I'm already notifying the user if the app is closed or in background. But I want to display a UIAlertView while the app is running. I tried to dispatch_async as follows but the alert is popping forever: [NSThread sleepForTimeInterval:minutes]; dispatch_async(dispatch_get_main_queue(), ^{ UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"title!" message:@"message!" delegate:self

How do I post a NSNotification when using Grand Central Dispatch?

╄→гoц情女王★ 提交于 2019-12-30 07:11:05
问题 I found that as predicted when I was writing an image to file that my UI was blocked for the duration, which was not acceptable. When I write the image to file I then post an NS Notification so that I can do some other specific jobs related to that completion. Original working but UI blocking code: -(void)saveImageToFile { NSString *imagePath = [self photoFilePath]; BOOL jpgData = [UIImageJPEGRepresentation([[self captureManager] stillImage], 0.5) writeToFile:imagePath atomically:YES]; if