grand-central-dispatch

What is the correct way to release a GCD dispatch queue property?

半腔热情 提交于 2019-12-21 06:58:13
问题 I'm using a dispatch_queue which is accessed through a property of its owner, like this: @property (nonatomic, assign) dispatch_queue_t queue; Note the assign keyword. The queue is used throughout the objects life and thus owned by the object. I release the queue when the owning object is deallocated: -(void)dealloc { dispatch_release(self.queue); self.queue = nil; } How do I properly release this? Would using retain/release work? What happens if there is stuff pending/running on the queue

Delaying Code Execution on OSX 10.10

馋奶兔 提交于 2019-12-21 06:16:13
问题 I've encountered a very strange issue that affects my code running only on OSX 10.10 systems. I've seen this anomaly occur on over 25 OSX 10.10 systems running my code, whereas the exact same code did not exhibit this behavior before upgrading (10.7). Furthermore, this issue is not 100% reproducible in that it occurs randomly ~0-5% of the time. While testing the code, nothing else critical or CPU exhaustive is occurring on the machine. Even if something else was happening, the very fact that

GCD: How to change timer fire interval

你。 提交于 2019-12-21 04:43:15
问题 This may sound a newbie question anyway, I'm very new to GCD I've following code : int interval = 2; int leeway = 0; dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue); if (timer) { dispatch_source_set_timer(timer, dispatch_walltime(DISPATCH_TIME_NOW, NSEC_PER_SEC * interval), interval * NSEC_PER_SEC, leeway); dispatch_source_set_event_handler(timer, ^{ [self

How does a serial queue/private dispatch queue know when a task is complete?

故事扮演 提交于 2019-12-21 04:31:45
问题 (Perhaps answered by How does a serial dispatch queue guarantee resource protection? but I don't understand how) Question How does gcd know when an asynchronous task (e.g. network task) is finished? Should I be using dispatch_retain and dispatch_release for this purpose? Update: I cannot call either of these methods with ARC... What do? Details I am interacting with a 3rd party library that does a lot of network access. I have created a wrapper via a small class that basically offers all the

GCD with NSURLConnection

◇◆丶佛笑我妖孽 提交于 2019-12-21 04:30:59
问题 I am using GCD to send HTTP request asynchronously. Here is the code that doesn't work: dispatch_async(connectionQueue, ^{ NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; [request setURL:[NSURL URLWithString:[NSString stringWithFormat:someURL]]]; NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; [connection start];//Not working }); the above code is not working at all. I am not getting any call back in NSURLConnectionDelegate's

Is NSNotificationCenter thread safe?

不打扰是莪最后的温柔 提交于 2019-12-21 03:52:25
问题 Can I post a notification in a given queue and receive it on another? I want to use notifications to communicate different queues, but I'm not sure if this is safe... 回答1: No. Notifications are delivered in the same thread that they are sent from, this you will need to re-send it in some way to get the notification to your thread. 回答2: No. Apple's docs on the subject say: " Regular notification centers deliver notifications on the thread in which the notification was posted. [...] At times,

dispatch_async block on main queue is never execeuted

浪尽此生 提交于 2019-12-21 03:25:09
问题 I have an app that uses a connection queue that handles the connections on a background thread. Each connection sends a JSON post, then when it receives a success, saves some objects into coredata. Once all connections are complete, i call a dispatch_async on the main thread to call a finished method. However, under very specific conditions of data im sending/saving, I've noticed the dispatch_async block to the main thread never gets called, and the app screen freezes, all execution stops,

UITableViewCell textLabel, does not update until a scroll, or touch happens, while using GCD

流过昼夜 提交于 2019-12-21 03:18:27
问题 Can someone help me figure this out please? My UITableViewCell textLabel , does not update until I scroll , or touch it. The ViewController loads, it shows the right amount of cells . But the content is blank. I have to touch it or scroll to make my textLabel appear. Am I doing something wrong here? - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView

In unit test, execute the block passed in queue with dispatch_asyc

徘徊边缘 提交于 2019-12-21 03:01:29
问题 If I dispatch_async a block on main queue like this: -(void) myTask { dispatch_async(dispatch_get_main_queue(), ^{ [self.service fetchData]; }); } In unit test, I can execute the block passed in main queue by manually run the main loop like this: -(void)testMyTask{ // call function under test [myObj myTask]; // run the main loop manually! [[NSRunLoop mainRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]]; // now I can verify the function 'fetchData' in block is called ... } Now

loading image in UITableViewCell asynchronously

痞子三分冷 提交于 2019-12-21 03:01:27
问题 What is the super very easy way to load the image in the UITableViewCell asynchronously say given a imageURL without having to subclassing the UITableViewCell, i.e: standard UITableViewCell 回答1: The easiest way I know is to use SDWebImage library. Here is a link that explains how to utilize the SDWebImage library to load avatars asynchronously. SDWebImage is an extension to the ImageView. Here is the usage: // load the avatar using SDWebImage [cell.imageView setImageWithURL:[NSURL