grand-central-dispatch

UITableView endUpdates not being called in dispatch_async

一世执手 提交于 2019-12-13 04:38:32
问题 I have several table views that send JSON requests to a server, store the results in core data, and display them using an NSFetchedResultsController . I was experimenting with GCD as follows: dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ // Perform JSON requests. dispatch_async(dispatch_get_main_queue(), ^{ [theTableView reloadData]; }); }); However, this would cause some weird things to happen in the UI. New managed objects would render blank cells, deleted

How to return an UIImage type from a GCD

时光毁灭记忆、已成空白 提交于 2019-12-13 03:59:19
问题 I have an "UIImage" return type method named "ComLog". I want to return a Image from this method. In "ComLog" method i use GCD to get the image value from an array. I use the following code, the "NSLog(@"qqqqqqqqqqq %@", exiIco)" print the 'image' value but NSLog(@"qqqqqqqqqqq %@", exiIco);" don't. Here is the details : -(UIImage*) ComLog { ExibitorInfo *currentExibitor100 = [[ExibitorInfo alloc] init]; currentExibitor100 = [self.exibitorsArray objectAtIndex:0]; imageQueueCompanyLogo =

What does 'DispatchQueue.main.async' and 'completed: @escaping () -> ()' mean in this snippet of code?

巧了我就是萌 提交于 2019-12-13 03:44:35
问题 Basically this is a simple project that involves a tableview that is updated according to data that is parsed from JSON from an api. I believe DispatchQueue.main.async and completed: @escaping () -> () have something to do with updating/reloading the tableview but I'm not sure how it works. Explanation would be appreciated on what these two do. import UIKit class ViewController: UIViewController { @IBOutlet weak var tableView: UITableView! var heroes = [HeroStats]() override func viewDidLoad(

In Swift, why GCD is not working with parse?

∥☆過路亽.° 提交于 2019-12-13 03:41:19
问题 I have already asked this on In Swift, how to stop all the process until datas retrieved from parse.com in UICOLLECTIONVIEW. I couldn't retrieve the datas from parse.com before next function get executed. I don't know how to access asynchronous thread. I have declared main queue to be "first_fun()", so this should be run first. Likewise, it is running first, but ending at last. Before that, next function ("second_fun()") gets executed. How to QUEUE this function block? How to finish

GCD and for loops

戏子无情 提交于 2019-12-13 02:39:24
问题 I was wondering what is the difference between using a for loop, and using the dispatch_apply function of GCD and couldn't find an answer in the documentation nor in questions here. Also, will using the GCD function in a runtime situation as a GLKit render/update method will produce better results? 回答1: Also, will using the GCD function in a runtime situation as a GLKit render/update method will produce better results? The only way to answer that question is to try it and measure the

GCD dispatch_barrier or dispatch_sync?

寵の児 提交于 2019-12-13 02:38:29
问题 I have some questions about dispatch_barrier and dispatch_sync . Here's the code: - (void)addPhoto:(Photo *)photo { if (photo) { // 1 dispatch_barrier_async(self.concurrentPhotoQueue, ^{ // 2 [_photosArray addObject:photo]; // 3 dispatch_async(dispatch_get_main_queue(), ^{ // 4 [self postContentAddedNotification]; }); }); } } - (NSArray *)photos { __block NSArray *array; // 1 dispatch_sync(self.concurrentPhotoQueue, ^{ // 2 array = [NSArray arrayWithArray:_photosArray]; // 3 }); return array;

Making sure I'm explaining nested GCD correctly

拟墨画扇 提交于 2019-12-13 02:13:48
问题 So I'm putting 10 tasks on a concurrent queue using dispatch_async . They do not block the next task, and gets processed in order. My UI is responsive. for (int i = 0; i < 10; i++) { dispatch_async(concurrencyQueue, ^() { NSLog(@"..calling insertion method to insert record %d", i); dispatch_sync(serialQueue, ^() { //this is to simulate writing to database NSLog(@"----------START %d---------", i); [NSThread sleepForTimeInterval:1.0f]; NSLog(@"--------FINISHED %d--------", i); }); }); } Within

How many dispatch_queue's should one make? Less is better or more is better?

巧了我就是萌 提交于 2019-12-13 01:33:41
问题 I have 10 instances of a class which need to do some background tasks. This should happen serially for the instances, but could be concurrent in regards to that the instances can do work independent of each other. Which is most cost effective in terms of speed and battery? When do I need to be concerned that I've created too many queues? This one (A) ? - (dispatch_queue_t)queue { static dispatch_queue_t queue; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ queue = dispatch

Why is asynchronous network testing difficult in Objective-C/Swift?

倖福魔咒の 提交于 2019-12-13 01:29:31
问题 So I'm learning more about how to test asynchronous code when I come across the following: As soon as a given test method completes, XCTest methods will consider a test to be finished and move onto the next test. That means that any asynchronous code from the previous test will continue to run while the next test is running. Networking code is usually asynchronous, since you don’t want to block the main thread while performing a network fetch. That, coupled with the fact that tests finish

imageWithCGImage: GCD memory issue

梦想与她 提交于 2019-12-13 00:48:10
问题 When I perform the following only on the main thread iref gets autoreleased immediately: -(void)loadImage:(ALAsset*)asset{ @autoreleasepool { ALAssetRepresentation* rep = [asset defaultRepresentation]; CGImageRef iref = [rep fullScreenImage]; UIImage* image = [UIImage imageWithCGImage:iref scale:[rep scale] orientation:UIImageOrientationUp]; [self.imageView setImage:image]; } } But when I perform imageWithCGImage: with GCD on a background thread iref does not get released instantly like in