grand-central-dispatch

How to wait for threading blocks to finish

回眸只為那壹抹淺笑 提交于 2019-12-23 05:27:40
问题 I am having issues with threading in my app. This is the first time I have used both AFNetworking and Parse. The problem is that I am calling both features and they both are required to finish before moving onto the next segue. Here is my code. The first block is for the network request using AFHTTP and the second is the parse request. AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; NSDictionary *parameters = @{@"foo": @"bar"}; [manager POST:@"http://example

GCD and foreign thread

你。 提交于 2019-12-23 05:23:27
问题 Is there a way I can create a new (or associate an existing) dispatch queue and tie it to a specific thread? I have an AudioUnit callback proc running on a thread I do not control and would like, prior to executing the callback proper, check if some given queue has any block for me to process within that AudioUnit thread. I can probably use OSAmtomicEnqueue and friends, but was wondering whether GCD already offered some kind of "escape" allowing me to tie a specific thread to a specific queue

Display multiple views serially using GCD

帅比萌擦擦* 提交于 2019-12-23 05:12:35
问题 I have 4 tabs and all have UIWebView . I want that the first tab should load and displayed immediately without waiting for others to load. For which I did this in UITabBarController class: for(UIViewController * viewController in self.viewControllers){ if(![[NSUserDefaults standardUserDefaults]boolForKey:@"isSessionExpired"]) { if((int)[self.viewControllers indexOfObject:viewController] != 4) { viewController.tabBarItem.tag = (int)[[self viewControllers] indexOfObject:viewController];

AudioUnit callback and synchronization: how to ensure thread safety with GCD

强颜欢笑 提交于 2019-12-23 04:33:24
问题 I am building an audio app based on the AudioUnit callback facility and a graph of audio processing nodes. I know that the callback is executed in a separate (high priority?) thread and therefore all interaction with my processing nodes, such as e.g. changing EQ parameters while playing, should be done in a thread safe manner. In other words, the nodes should be protected from modification while the audio callback chain is being executed. The way I understand it in terms of more low-level

Load UIImagePickerController faster?

余生长醉 提交于 2019-12-23 04:22:17
问题 I need to load UIImagePickerController faster. My app will call UIImagePickerController from possibly multiple controllers and within each controller there are two buttons, one for Photo Library, another for Camera. This is my sample app. Some solutions I tried are recommended by Apple in ' Concurrency Programming Guide '. The simplest is to alloc & init an instance when user presses a button. This can take up to 2 seconds before the camera shows up. Solution attempt:- (1) I made a @property

GCD global concurrent queue not always concurrent(iOS device)?

有些话、适合烂在心里 提交于 2019-12-23 03:27:48
问题 On iOS device, I recently found that a strange behavior. Code1: dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSLog(@"1111"); }); while (1) { sleep(1); } }); Code2: dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSLog(@"1111"); }); while (1) { sleep(0.5); } });

calling asynchronous method inside for-loop [duplicate]

断了今生、忘了曾经 提交于 2019-12-23 03:15:52
问题 This question already has answers here : What's the best way to iterate over results from an APi, and know when it's finished? (1 answer) Swift Closures in for loop (1 answer) How do you run code after an async call finishes and the code is outside of the asyn function in swift3 (1 answer) Closed last year . Trying to make my for loop behave synchronously when I am making an asynchronous call in each iteration of the loop. I have a feeling I will need to use Grand Central Dispatch in some way

calling asynchronous method inside for-loop [duplicate]

大兔子大兔子 提交于 2019-12-23 03:15:09
问题 This question already has answers here : What's the best way to iterate over results from an APi, and know when it's finished? (1 answer) Swift Closures in for loop (1 answer) How do you run code after an async call finishes and the code is outside of the asyn function in swift3 (1 answer) Closed last year . Trying to make my for loop behave synchronously when I am making an asynchronous call in each iteration of the loop. I have a feeling I will need to use Grand Central Dispatch in some way

GCD implementation on a UITableView

陌路散爱 提交于 2019-12-23 01:45:16
问题 I am doing some heavy calculations when I am creating cells. I am trying to figure out the best way to keep the UITableView fluid, but at the same type do the calculations on the background (keep the UI thread without too much processing). For testing purposes only, I am using this as my heavy calculation method: +(NSString*)bigCalculation { int finalValue=0; int j=0; int i=0; for (i=0; i<1000; i++) { for (j=0; j<10000000; j++) { j++; } finalValue+=j/100*i; } return [NSString stringWithFormat

Running multiple background threads iOS

99封情书 提交于 2019-12-23 01:41:12
问题 Is it possible to run multiple background threads to improve performance on iOS . Currently I am using the following code for sending lets say 50 network requests on background thread like this: dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){ // send 50 network requests }); EDIT: After updating my code to something like this no performance gain was achieved :( Taken from here dispatch_queue_t fetchQ = dispatch_queue_create("Multiple Async Downloader",