nsoperationqueue

substituting for __weak when not using ARC

╄→гoц情女王★ 提交于 2019-12-21 05:22:14
问题 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

NSOperationQueue not working in IOS5

六眼飞鱼酱① 提交于 2019-12-21 02:27:31
问题 I have a project which downloads images in background using NSOperationQueue . It was working until now on devices with IOS 4.3. However if I build the app with base sdk 4.3 or with 5 and run the app on device with IOS5, the app crashes. When app is launched, it adds NSOperation objects into queue for downloading the images. If in between I press back button, I cancel the NSOperation and it crashes and displays following trace on console: #0 0x004727b7 in ____NSOQSchedule_block_invoke_0 () #1

Executing the NSOperation when all other operations in NSOperationQueue finished no matter whether they finished successfully or not

早过忘川 提交于 2019-12-19 04:06:23
问题 Hi I have a strange situation here : OverView: I am working on an app where user can initiate multiple operations and all these operations will run on a background thread hence will not block the UI. Some of these operations are dependent on each other and some are not. So in order to ensure that operation will execute only after all the necessary dependencies operations finished executing am using the dependency property of Operation. I am making use of Asynchronous operations. Here is my

Wait for all Operations in queue to finish before performing task

混江龙づ霸主 提交于 2019-12-18 15:54:15
问题 I have an Operation subclass and Operation queue with maxConcurrentOperationCount = 1. This performs my operations in a sequential order that i add them which is good but now i need to wait until all operations have finished before running another process. i was trying to use notification group but as this is run in a for loop as soon as the operations have been added to the queue the notification group fires.. How do i wait for all operations to leave the queue before running another process

How can an NSOperationQueue wait for two async operations?

痴心易碎 提交于 2019-12-18 12:34:59
问题 How can I make an NSOperationQueue (or anything else) wait for two async network calls with callbacks? The flow needs to look like this Block Begins { Network call with call back/block begins { first network call is done } } Second Block Begins { Network call with call back/block begins { second network call is done } } Only run this block once the NETWORK CALLS are done { blah } Here's what I have so far. NSOperationQueue *queue = [[NSOperationQueue alloc] init]; __block NSString *var;

Asynchronous url requests inside dispatch_async

青春壹個敷衍的年華 提交于 2019-12-18 11:15:12
问题 I am trying to implement asynchronous url requests in a particular function, I want all these requests to complete and then do a particular action but the action precedes the requests i.e, it is getting called before the requests complete. dispatch_queue_t fetchQ = dispatch_queue_create("Featured Doc Downloader", NULL); dispatch_async(fetchQ, ^{ [self myAsyncMultipleURLRequestFunction]; dispatch_sync(dispatch_get_main_queue(), ^{ [self updateUIFunction]; }); }); -(void

Hold NSOperationQueue until previous operation completes

妖精的绣舞 提交于 2019-12-18 03:48:10
问题 I want to perform few operations and need to start the next operation only upon completion of the previous one. The operation I'm adding will send async call to the server and receive data. I want to start the next operation only after the first call to the server finish receiving data from the server. How to do that? {.... PhotoDownloader *pd = [[PhotoDownloader alloc] init]; [GetGlobalOperationQueue addOperation:pd]; } Inside the PhotoDownloader I will allocate the required parameters and

Default value of maxConcurrentOperationCount for NSOperationQueue

橙三吉。 提交于 2019-12-17 16:32:13
问题 As the title suggests, what is the default value of the maxConcurrentOperationCount for NSOperationQueue? Is it set to a value of 1? 回答1: From the documentation, The maximum number of concurrent operations set explicitly on the receiver using the setMaxConcurrentOperationCount: method. If no value has been explicitly set, this method returns NSOperationQueueDefaultMaxConcurrentOperationCount by default . So it is NSOperationQueueDefaultMaxConcurrentOperationCount . If this is set, it will

Generic NSOperation subclass loses NSOperation functionality

时光毁灭记忆、已成空白 提交于 2019-12-17 09:47:17
问题 Today I've met one weird issue when I was trying to 'generalize' my 'CoreData importing operations'. It appeared that if I create a generic subclass of NSOperation the main() func won't be called. Simple example: class MyOperation<T: NSObject>: NSOperation { override func main() { println("My operation main was called") } } If you create an instance of this class and add it to the operationQueue you will see that it's main() isn't actually called. override func viewDidLoad() { super

How to cancel NSBlockOperation

不问归期 提交于 2019-12-17 08:18:08
问题 I have a long running loop I want to run in the background with an NSOperation . I'd like to use a block: NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{ while(/* not canceled*/){ //do something... } }]; The question is, how to I check to see if it's canceled. The block doesn't take any arguments, and operation is nil at the time it's captured by the block. Is there no way to cancel block operations? 回答1: Doh. Dear future googlers: of course operation is nil when