Gcd asynchronous multi-thread operation process. Generally, data is processed in sub-threads, and the main thread updates the interface.
static dispatch_queue_t loadDealersQueue = NULL; if (!loadDealersQueue) { loadDealersQueue = dispatch_queue_create("com.geelycar.loadactivity.loaddealersqueue", NULL); } dispatch_async(loadDealersQueue, ^{ @autoreleasepool { //Data processing dispatch_async(dispatch_get_main_queue(), ^{ //Update Interface }); } });
Today I have another insight. Let's take a look at the following subthreads and main thread calls:
Static dispatch_queue_t searchQueue = NULL; if (! SearchQueue) searchQueue = dispatch_queue_create ("com. moneytree. searchqueue", NULL); // scheduling queue
// Run dispatch_async asynchronously (searchQueue, ^ {@ autoreleasepool {// write Method for automatically releasing a pool in ARC Mode
// Put data processing in the queue NSArray * resultData = [[NSArray alloc] initWithArray: [[MTStockManage sharedInstance] stockListMatchingSearchText: searchText fromArray: self. stockList]; self. stockList = resultData; [self setTableDataSource: nil]; if (resultData. count> SHOW_STOCK_NUMBER) {nsange range = NSMakeRange (0, SHOW_STOCK_NUMBER); [self setTableDataSource: [resultData subarrayWithRange: range];} else {[self setTableDataSource: resultData];} dispatch_async (dispatch_get_main_queue (), ^ {// return to the main interface [self. dataResultTable reloadData]; // refresh the UI in the main thread });}});