nsoperation

Serializing asynchronous tasks in objective C

China☆狼群 提交于 2019-12-06 05:15:02
问题 I wanted to be able to serialize 'genuinely' async methods, for example: making a web request showing a UIAlertView This is typically a tricky business and most samples of serial queues show a 'sleep' in an NSBlockOperation's block. This doesn't work, because the operation is only complete when the callback happens. I've had a go at implementing this by subclassing NSOperation, here's the most interesting bits of the implementation: + (MYOperation *)operationWithBlock:(CompleteBlock)block {

Pass data from NSOperation to next NSOperation

时光怂恿深爱的人放手 提交于 2019-12-06 03:59:53
问题 Is it possible to pass data from an NSOperation up the dependency chain to be used by the next NSOperation? Thanks Chris 回答1: Yes. The current NSOperation can access it's dependancies via the dependencies method: NSArray *myDependancies = [self dependencies]; It can then access whatever properties you wish on the previous operations and pull out any data it requires. In a recent project I found that I needed to pass data along so often that I created a subclass of NSOperation that

Magic of NSOperation internals - how does it observe isFinished key so that completionBlock is always run?

你说的曾经没有我的故事 提交于 2019-12-06 02:14:49
Demonstration - (void)test_NSOperationCallsCompletionBlockWhenFinished { __block BOOL flag = NO; NSOperation *operation = [NSOperation new]; operation.completionBlock = ^{ NSLog(@"Hunting NSOperation internals: %@", [NSThread callStackSymbols]); flag = YES; }; [operation start]; while (flag == NO); STAssertTrue(flag, nil); } Gives me the following input: 2013-07-28 19:59:44.690 SACompositeOperationsApp[99551:3103] Hunting NSOperation internals: ( 0 SACompositeOperationsApp 0x000000010005bbd9 __68-[SAOperationTests test_NSOperationCallsCompletionBlockWhenFinished]_block_invoke + 41 1 Foundation

Fixing my network activity indicator

岁酱吖の 提交于 2019-12-05 21:36:00
I have a problem with my network activity indicator in that sometimes it will continue to be displayed when it should not be. I wrote my own manager for it and swapped it out for one that uses an NSAssert statement like this... - (void)setNetworkActivityIndicatorVisible:(BOOL)setVisible { static NSInteger NumberOfCallsToSetVisible = 0; if (setVisible) NumberOfCallsToSetVisible++; else NumberOfCallsToSetVisible--; // The assertion helps to find programmer errors in activity indicator management. // Since a negative NumberOfCallsToSetVisible is not a fatal error, // it should probably be removed

Why is my NSOperation subclass never finishing?

北战南征 提交于 2019-12-05 15:43:35
I have an NSOperation subclass that I want to run concurrently. My understanding is that for concurrent operations to work: I need to define isConcurrent to return YES . I need to define the start method I need to send KVOs notification for isExecuting and isFinished when it's done. Using @synthesize will automatically send the appropriate KVO notifications when the values for isExecuting and isFinished are changed. Despite this, I have verified that my queue never moves on to the next item. Here's the meat of my code: @interface MyOperation() @property (readwrite) BOOL isExecuting; @property

NSOperation KVO isFinished

前提是你 提交于 2019-12-05 14:31:54
Im trying to subclass a NSOperation, and read some sample from, they say: when the task finished, using KVO of NSOperation, to finish the operation, code here: [self willChangeValueForKey:@"isFinished"]; [self willChangeValueForKey:@"isExecuting"] finished = YES; executing = NO; [self didChangeValueForKey:@"isFinished"]; [self didChangeValueForKey:@"isExecuting"]; then isFinished get called - (BOOL) isFinished{ return(finished); } anyone could explain this to me? why isFinished gets called, will the isFinished finish the operation? as I understanded, do KVO manually need [self

Subclassing NSOperation to internet operations with retry

孤街浪徒 提交于 2019-12-05 13:46:21
I'm subclassing NSOperation for http post in background thread. Those specific http posts doesn't require any value to return. What I'm trying to do is when I've an error or timeout I want it to send after an increasing delay (fibonacci). So far I've done this: NSInternetOperation.h: #import <Foundation/Foundation.h> @interface NSInternetOperation : NSOperation @property (nonatomic) BOOL executing; @property (nonatomic) BOOL finished; @property (nonatomic) BOOL completed; @property (nonatomic) BOOL cancelled; - (id)initWebServiceName:(NSString*)webServiceName andPerameters:(NSString*

Passing Data Between Two NSOperations

本秂侑毒 提交于 2019-12-05 10:17:35
问题 I watched with a great attention the WWDC 2015 sessions about Advanced NSOperations and I played a little bit with the example code. The provided abstraction are really great, but there is something I may did not really good understand. I would like to pass result data between two consequent Operation subclasses without using a MOC. Imagine I have a APIQueryOperation which has a NSData? property and a second operation ParseJSONOperation consuming this property. How do I provide this NSData?

Should I use NSOperation or NSRunLoop?

倾然丶 夕夏残阳落幕 提交于 2019-12-05 07:48:03
问题 I am trying to monitor a stream of video output from a FireWire camera. I have created an Interface Builder interface with buttons and an NSImageView . While image monitoring is occurring within an endless loop, I want to: change some camera parameters on the fly (gain, gamma, etc.) tell the monitoring to stop so I can save an image to a file (set a flag that stops the while loop) Using the button features, I have been unable to loop the video frame monitor, while still looking for a button

NSOperationQueue, concurrent operation and thread

白昼怎懂夜的黑 提交于 2019-12-05 05:21:11
问题 I'm developing a sort of fast image scan application. In the -captureOutput:didOutputSampleBuffer:fromConnection: method I pick up the CVPixelBuffer and add them into an NSOperation subclass. The NSOperation takes the buffer and transform it into an image saved on the filesystem. The -isConcurrent method of NSOperation returns YES. After the operation is created, is added to an NSOperationQueue . Everything runs fine except for one issue that is affecting the scan frame rate. Using time