nsoperationqueue

How to remove/cancel NSInvocationOperation from NSOperationQueue?

二次信任 提交于 2019-12-03 17:33:52
Both of the following questions are being asked in context to maintain NSOperationQueue and NSInvocationOperation. As I have used this concept to download multiple videos, how do I remove/release added NSInvocationOperation from NSOperationQueue after completion of downloading a video? And also, what should I do if in case I want to stop to download specific video while the process of downloading in progress? how do I remove/release added NSInvocationOperation from NSOperationQueue after completion of downloading a video? The operation is automatically removed from the queue when it has

substituting for __weak when not using ARC

淺唱寂寞╮ 提交于 2019-12-03 16:15:06
I have this line of code: __weak NSBlockOperation *weakOperation = operation; which is triggering this compiler error: __weak attribute cannot be specified on automatic variable. Reason for this is I don't have ARC enabled (not ready to make the switch just yet). So from another StackOverFlow question, I was recommended to use: __unsafe_unretained NSBlockOperation *weakOperation = operation; Which makes the error go away, but for the context I'm using it, it's not working (see this question if interested: How to cancel NSOperationQueue ). So my question is, what I can substitute the __weak

How can I Pause a NSOperation in a NSOperationQueue?

女生的网名这么多〃 提交于 2019-12-03 15:37:44
问题 I need to pause a running NSOperation which was inserted in an NSOperationQueue. Currently I am canceling all operations and restarting them. But this would lead to some kind of duplication in terms of process done. I tried with setSuspended flag of NSOperationQueue. But it's not suspending the operation. Is there any way out? 回答1: see this: Link And here from the apple docs: Suspending and Resuming Queues If you want to issue a temporary halt to the execution of operations, you can suspend

AFNetworking + NsOperationQueue - Download thousands of Images

假如想象 提交于 2019-12-03 12:49:05
问题 I am working on a task (iOS5 + only) that involves downloading thousands of images from the server. The images belong to certain categories and each category can have hundreds of images. What I need to do is this :- 1) Make sure the app downloads any missing images in background if the app is active (even when the user is browsing some other areas of the app that are not related to photos). 2) When the user clicks on a Photo Category, the images in that Category must be downloaded as high

GCD, NSOperationQueue, or create a thread manually?

余生颓废 提交于 2019-12-03 12:38:33
问题 When you use threads, do you have any preferences? In general rule, to use any of these techniques : create a new thread manually and use the run loop use NSOperationQueue or use Grand Central Dispatch and the C version with dispatch_queue? Does NSOperationQueue simplify everything, and thus is better to be used when we need to create an asynchronous function? 回答1: I'm lazy, so my philosophy is to pick the simplest solution that does everything I need it to. (I like to think this is the "lazy

How can I better optimize networking on iOS?

不羁岁月 提交于 2019-12-03 11:39:33
问题 I have created a project on GitHub so I can learn how to optimize networking for my iOS apps. I have used blocks and GCD heavily and after watching WWDC 2012 videos and videos from past years I learned that I may be able to do more with NSOperationQueue. Specifically I can control the number of concurrent operations (network connections) as well as provide cancellation of operations. I am experimenting with allowing 1, 2, 4, 8 and 16 concurrent operations and I am seeing interesting results

[NSOperation cancelAllOperations]; does not stop the operation

送分小仙女□ 提交于 2019-12-03 11:26:14
xCode 4.4.1 OSX 10.8.2, looks like [operation cancelAllOperations]; isn't working - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { NSOperationQueue *operation = [[NSOperationQueue alloc] init]; [operation setMaxConcurrentOperationCount: 1]; [operation addOperationWithBlock: ^{ for (unsigned i=0; i < 10000000; i++) { printf("%i\n",i); } }]; sleep(1); if ([operation operationCount] > 0) { [operation cancelAllOperations]; } } results 9999999 Inside your block, particularly inside the loop, call -isCancelled on the operation. If it's true, then return. NSOperationQueue

Pause NSOperation

浪尽此生 提交于 2019-12-03 09:57:20
问题 I have NSOperationQueue with some NSOperations in it ( NSInvocationOperations , in particular). This operations do some calculations and change states of UI elements accordingly (of course, via performSelectorOnMainThread:... ), often with use of animations. My UI has UINavigationViewController and some buttons for navigation to another views. So user can leave current view, while calculations / animations are still in progress. And what I need is to stop this somehow until user comes back to

Fetching Core Data in the background

久未见 提交于 2019-12-03 08:51:41
问题 I have a Navigation View with a Table View, when a row is clicked, the row indexPath is passed to the next view. in the Details view viewDidLoad, i am fetching data from Core Data. i use the fetching from the application delegate [appDelegate loadItem:i]; As you can see i am passing one integer only which carries the row number. the question is: How can i make this call process in another thread.(in the background) I need this because sometimes the result of the fetch is too big, so the

OperationQueue.main vs DispatchQueue.main

女生的网名这么多〃 提交于 2019-12-03 08:27:28
问题 When you need to perform something on the main thread in the completion block of a networking task or an operation, which of these ways to get it would be the most appropriate and why?: OperationQueue.main.addOperation DispatchQueue.main.async 回答1: For details on the differences between the two types of queue, see Lion's answer. Both approaches will work. However, NSOperation is mostly needed when more advanced scheduling (including dependencies , canceling , etc.) is required. So in this