grand-central-dispatch

What's wrong with this dealloc in ARC?

若如初见. 提交于 2019-12-10 09:44:41
问题 I am working on an app that does image processing and displays the resulting image. Im using UIScrollView to let user scroll all images, because the image is not a standard jpg or png, it takes time to load. I use GCD to load asynchronously, when finished dispatch to main queue to display. the snippet is as follows: - (void)loadImage:(NSString *)name { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ UIImage *image = [Reader loadImage:name]; dispatch_sync

How do I return from a getter of an asynchronous property?

限于喜欢 提交于 2019-12-10 04:10:34
问题 I have over-ridden a getter that requests an online service to get a result. How do I force the getter to return the result only from synchronous block ? @interface MyClass () @property (nonatomic, strong) NSMutableDictionary* myDictionary; @end @implementation MyClass -(NSMutableDictionary*) myDictionary { dispatch_async(queue, ^{ /* perform online request */ dispatch_sync(dispatch_get_main_queue(), ^{ // I need to obtain lock until this line gets executed and only then return }); }); } @end

dispatch_semaphore_t reuse - What am I missing here?

二次信任 提交于 2019-12-10 03:37:57
问题 I have some code where I am using dispatch_semaphore_t to signal operation completion. When the semaphore is a member variable, it does not seem to behave correctly. I will show example code that works and an example that does not seem to work: @implementation someClass { dispatch_semaphore_t memberSem; dispatch_semaphore_t* semPtr; NSThread* worker; BOOL taskDone; } - (id)init { // Set up the worker thread and launch it - not shown here. memberSem= dispatch_semaphore_create(0); semPtr= NULL;

How do we dispatch Google Analytics events when iOS app goes to the background?

a 夏天 提交于 2019-12-10 03:16:46
问题 My iOS app has links to Apple's App Store in it and I am trying to track those as events. The problem is that we can't get my app to properly dispatch the GA events before it goes into the background. We are using iOS SDK v2beta4. Here is an overview of the code we are using. You can see we've put in a lot of what I call "insurance policy" code because what we think is the correct way is not working. But even the insurance policy code does not always dispatch the events before my app goes

Crashed: com.apple.root.default-qos

倾然丶 夕夏残阳落幕 提交于 2019-12-10 02:19:12
问题 I have a fairly simple app that parses a RSS feed and shows it's content in a table view. It's available on the App Store. I have Crashlytics crash reporting integrated. I recently received two reports. These are a little difficult to decipher. This has occurred in an iPhone 6 running iOS 10.2.1. This is from an iPhone 5 running iOS 10.2.1. Even though it says it's crashing due to privacy violations, I'm not accessing any services that requires permission in my app. Also searching on com

Why should we separate alloc and init calls to avoid deadlocks in Objective-C?

元气小坏坏 提交于 2019-12-10 01:50:21
问题 When reading about thread-safe singletons I found Thread safe instantiation of a singleton here on SO, and in the accepted answer this code: sharedInstance = [MyClass alloc]; sharedInstance = [sharedInstance init]; Why should we separate alloc and init methods? The author of the answer wrote: Namely, if the init of the class being allocated happens to call the sharedInstance method, it will do so before the variable is set. In both cases it will lead to a deadlock. This is the one time that

dispatch_async timeout method call

雨燕双飞 提交于 2019-12-09 23:41:29
问题 Is there a good way to call an external method after a set time limit for completing the long process outlined below? I would like the long process to stop trying after a set interval and call a method to try something else and wrap up the request. dispatch_async(dispatch_get_global_queue(0, 0), ^{ //// LONG PROCESS dispatch_async(dispatch_get_main_queue(), ^{ //// RESULTS PROCESS }); }); 回答1: In order to "kill" the process that's running your block, you'll have to check a condition. This

When to dispatch_release()?

一曲冷凌霜 提交于 2019-12-09 17:59:01
问题 I'm fairly new to GCD and was trying to find an answer to this. Assuming I have the following code: dispatch_queue_t queue = dispatch_queue_create("queue", NULL); dispatch_async(queue, ^{ // do some stuff }); Where in the code should I release the queue? Inside or outside the block? 回答1: Outside the block. I'm fairly certain you don't have to wait for the async block to finish as GCD will retain the queue. 来源: https://stackoverflow.com/questions/4842460/when-to-dispatch-release

How to safely decouple rendering from updating the model?

风流意气都作罢 提交于 2019-12-09 16:02:26
问题 Talking with some game developers, they suggested that a performant OpenGL ES based game engine does not handle everything on the main thread. This allows the game engine to perform better on devices with multiple CPU cores. They said that I could decouple updates from rendering. So if I understood this correct, a game engine run loop can work like this: Setup a CADisplayLink which calls a render method. render method renders current world model in background. render method then calls update

Is there any reason to not use sleep in a Grand Central Dispatch queue?

落爺英雄遲暮 提交于 2019-12-09 15:25:12
问题 I would like to make a queue wait for a short period while it is looping. I am considering my options and was testing out suspending a resuming a queue but that seems to require several moving parts. So I am considering using sleep or usleep instead. That is more of a general threading function and would like to know if I should avoid using sleep and instead stick with GCD options to make a queue pause. I found one related question but that answer shows that he was just missing an include.