grand-central-dispatch

Reload UICollectionViewCell which has image

前提是你 提交于 2019-12-24 18:53:27
问题 I am trying to create something like Facebook NewsFeed where, I am using custom UICollectionViewCell to display data (Text/Image) from JSON. I have 2 different APIs. One for text and another for images(Every cell doesn't have image). So, First of all I am getting all text values in to my cells from my textAPI and reloading myCollectionView. That works perfect. Now for the Images, I am using ImageFetcher to fetch images, func ImageFetcher(postId : NSNumber, completion : ((_ image: UIImage?) ->

Load UIImage from file using grand central dispatch

不问归期 提交于 2019-12-24 17:52:06
问题 I'm trying to load images in the background using gcd. My first attempt didn't work: dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW,0), ^{ dispatch_async(dispatch_get_main_queue(), ^{ // create UI Image, add to subview }); }); commenting out the background queue code and leaving just the main queue dispatch block didn't work: dispatch_async(dispatch_get_main_queue(), ^{ // create UI Image, add to subview }); Is there some trick to doing ui stuff inside a gcd block? In

Loading data after one second in uitableview. Any alternate way to eliminate this delay

半城伤御伤魂 提交于 2019-12-24 16:27:06
问题 NSURL *url=[NSURL URLWithString:string]; dispatch_queue_t backgroundQueue = dispatch_queue_create("com.example.workQueue", DISPATCH_QUEUE_SERIAL); dispatch_async(backgroundQueue, ^{ NSData *data=[NSData dataWithContentsOfURL:url]; NSDictionary *json=[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil]; NSLog(@"%@",json); marray=[NSMutableArray array]; for (NSDictionary *dict in json) { } dispatch_async(dispatch_get_main_queue(), ^{ [self.tableView reloadData]; }); });

Update property using Geocoder to get user actual address, EXC_BAD_ACCESS

…衆ロ難τιáo~ 提交于 2019-12-24 14:26:03
问题 Im relatively a new iOS developer, and im dealing with the geocoder completion handler , i do not understand how to update a variable with the address find by the geocoder and the do some stuff with it. In few words, i want that the geocoder block finishes to use the info in some method . - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { NSLog(@"didUpdateToLocation: %@", newLocation); CLLocation

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

Is it possible to make dispatch_queue_t empty?

守給你的承諾、 提交于 2019-12-24 09:15:13
问题 I cannot find any information about it. I have a dispatch_queue_t in my application where I put some tasks to do. But these tasks take some time and it happens that sometimes they shouldn't be called any more so I would like to clean out queue. Is it possible? 回答1: Use NSOperationQueue for these capabilities - much more convenient. After adding operations to a queue, you can cancel them and even cancel all pending operations if needed. Here's a good tutorial to get you started: http://www

Why weird behavior of barrier on concurrent queue?

折月煮酒 提交于 2019-12-24 06:30:01
问题 I am trying to verify the functionality of dispatch_barrier_async , and use "points of interest" to check what happened. The code is as below: _syncQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); for (int index = 0; index < 3; ++index) { kdebug_signpost_start(0, 0, 0, 0, 0); dispatch_sync(_syncQueue, ^{ NSLog(@"sync@@@@@@ >>>> %d ",index); sleep(1); NSLog(@"sync@@@@@@ <<<< %d ",index); }); kdebug_signpost_end(0, 0, 0, 0, 0); } for (int index = 3; index < 6; ++index) {

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

Two simultaneous background tasks using NSOperationQueue

冷暖自知 提交于 2019-12-24 04:03:09
问题 I have two tasks that i need to perform in background simultaneously with different thread priorities: continuously gather and process gyro motion data (high priority) gyroQueue = [[NSOperationQueue alloc] init]; [self.motionManager startDeviceMotionUpdatesToQueue:gyroQueue withHandler:^(CMDeviceMotion *motion, NSError *error){ [self processMotion:motion withError:error]; }]; Sometimes process images without interfering with motion updates (convert, crop, sesize, etc = 1-2sec) (very low

How to run async operations within a grand central dispatch operation?

萝らか妹 提交于 2019-12-24 03:05:52
问题 I have a queue of jobs that need to be processed, the queue is periodically kicked by a timer but also by calling threads when a new job is added to the queue. When the queue is kicked I want to initiate the processing of the queue on another thread as I don't want to block the calling thread (Which in a lot of cases will be the UI thread). So to do this I run a grand central dispatch operation on the high priority concurrent queue, this creates an instance of my http class and submits the