nsoperation

Should I use NSOperation or NSRunLoop?

为君一笑 提交于 2019-12-03 23:15:46
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 press (much like using the keypressed feature from C.) Two options present themselves: Initiate a new

Passing Data Between Two NSOperations

ε祈祈猫儿з 提交于 2019-12-03 22:27:53
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? intance to the second operation ? I tried something like this : queryOperation = APIQueryOperation

NSOperation and SetImage

无人久伴 提交于 2019-12-03 20:27:55
I need to use a thread in order to retrieve an image from the web and assign it into an image view. I have subclassed NSOperation and called it from my view controller like: NSOperation *operation = [[[GetImage alloc] init] autorelease]; [queue addOperation:operation]; I get the image fine but how do I go about assigning that image that is in my NSOperation class? I have the image stored in a UIImage called RetrievedImage: NSData *imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:url]]; retrievedImage = [[UIImage alloc] initWithData:imageData]; [imageData release]; How do

Drawing in a background thread on iOS

社会主义新天地 提交于 2019-12-03 19:34:44
问题 I have a view with some very complex drawing logic (it's a map view that draws from GIS data). Doing this drawing on the main thread locks up the UI and makes the app unresponsive. I want to move away the drawing to a background thread with for example an NSOperation. What is the best way to structure this? I am currently drawing to an off memory CGContext and then convert that to a CGImageRef which I send to the view to blit on the main thread. Unfortunately this uses up a lot of memory and

How do I do an Asynchronous NSURLConnection inside an NSOperation?

六眼飞鱼酱① 提交于 2019-12-03 17:55:51
问题 I want to do an Asynchrous NSURLConnection inside of an NSOperation on a background thread. (it is because I'm doing some very expensive operations on the data as they come back that want to be done as the data comes in and in background) Here is my first attempt: IN my AppDelegate: // create the opperation and add it to the queue: self.sharedOperationQueue = [[[NSOperationQueue alloc] init] autorelease]; LibXMLOperation *op = [[[LibXMLOperation alloc] init] autorelease]; [self

CloudKit: CKFetchRecordChangesOperation, CKServerChangeToken and Delta Download

安稳与你 提交于 2019-12-03 16:36:32
My question is related to the "Delta Download" thing as it was named in WWDC 2014 Advanced CloudKit. I'm trying to make syncronization for my Core Data app, which is iPhone only for now (think: there is only one device active). So, basically the app will store user records in the cloud from one same device, for the most cases for now. I have trouble with understanding custom zone feature which is based on CKFetchRecordChangesOperation aka Delta Download. As I got it right, we have CKServerChangeToken 's to maintain sync operations (I mean download only those records which was added/modified

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

Referencing an NSOperation object in its own completion block with ARC

独自空忆成欢 提交于 2019-12-03 12:00:47
问题 I'm having difficulty converting some NSOperation code to ARC. My operation object uses a completion block, which in turn contains a GCD block that updates the UI on the main thread. Because I reference my operation object from inside its own completion block, I'm using a __weak pointer to avoid a memory leak. However, the pointer is already set to nil by the time my code runs. I've narrowed it down to this code sample. Anyone know where I went wrong, and the right way to accomplish this?

Core Data and NSOperation

眉间皱痕 提交于 2019-12-03 10:05:00
问题 I'm currently working with an NSPersistentDocument subclass that uses NSOperation to import data in the background. As per the documentation, I'm observing the NSManagedObjectContextDidSaveNotification after saving in the background task and propagating the notification to the NSManagedObjectContext in the main thread using -mergeChangesFromContextDidSaveNotification: . Everything works fine, but it presents a weird workflow for a user who's importing data into a new document. They need to

Cocoa - Return information from NSOperation

萝らか妹 提交于 2019-12-03 09:59:16
问题 I have an IPhone app that uses webservices to get data from a server. I'm putting each call to the webservice in a NSOperation subclass so that it can be threaded. My question is, what is the recommended way to pass back information from a completed NSOperation subclass. I'm currently sending a NSNotification at the end of my main method and any code that is waiting for the NSOperation to complete, subscribes to the notification. And then I will use the object part of NSNotificationWithName