nsoperation

NSOperation on the iPhone

I've been looking for some concrete scenarios for when NSOperation on the iPhone is an ideal tool to use in an application. To my understanding, this is a wrapper around writing your own threaded code. I haven't seen any Apple demo apps using it, and I'm wondering if I'm missing out on a great tool instead of using NSThread. The ideal s...

Get notification when NSOperationQueue finishes all tasks

NSOperationQueue has waitUntilAllOperationsAreFinished, but I don't want to wait synchronously for it. I just want to hide progress indicator in UI when queue finishes. What's the best way to accomplish this? I can't send notifications from my NSOperations, because I don't know which one is going to be last, and [queue operations] migh...

How use sqlite + fdbm library with threading on the iPhone

Related to this SO question, I want to put the data loading in the background. However, I get 'library routine called out of sequence' errors. In this SO thread say that the way is using NSOperation, but looking on the samples on the web I not know how that could solve the issue. I share a single sqlite connection with the singleton p...

NSOperation + Objective-C Categories = Bad Idea?

I've set up an Objective-C category for an iPhone app's UIImageView class. The category's mission is to help load URL-based images asynchronously with memory/disk caching. Now, in UIImageView+Cache.m I have access to an NSOperationQueue so I can kick off a loading thread. I create an NSOperation-derived object, initialized with the imag...

Cocoa - Return information from NSOperation

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 met...

Using NSOperation for threading creates too many objects

I have an app that makes SOAP calls. To keep the UI from blocking, we are putting each SOAP call into a subclass of NSOperation. This works well, but we have a ton of different types of SOAP calls. So if we use 3 WSDLs each with 10 Ports or Operations, then we 30 different calls in SOAP and if we put each of those in a thread using NS...

How do I do an Asychronous NSURLConnection inside an NSOperation?

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: s...

EXEC_BAD_ACCESS when using NSOperation

This is pretty much the same problem i have, except with very different code: http://www.cocoabuilder.com/archive/message/cocoa/2009/3/24/233015 I want to offload some processing to an NSOperation, passing a filename as a reference that the NSOperation loads and parses. The app crashes with EXEC_BAD_ACCESS when entering -(void)init. He...

How do I bind a NSProgressIndicator to a property of a NSOperation?

I've got a window which reflects the status of an NSOperation. How should I bind the NSProgressIndicator to the NSOperation's progress-property? ...

NSURLDownload delegate methods on a separate thread

Hey, Is anyone aware of a way to receive NSURLDownload's delegate methods on a separate thread, i.e. not the main one? I am using an NSOperationQueue to manage them but at the moment I need to use the performSelectorOnMainThread method to get it too work. The problem with this is that it drives the kernel task crazy reaching about 30% o...

How lightweight is NSOperationQueue on Snow Leopard?

I'm working with some code that does a bunch of asynchronous operating with various callbacks; Snow Leopard has made this incredibly easy with blocks and GCD. I'm calling NSTask from an NSBlockOperation like so: [self.queue addOperationWithBlock:^{ NSTask *task = [NSTask new]; NSPipe *newPipe = [NSPipe new]; NSFileHandle *r...

Is there a bug in NSOperation in Mac OS X 10.6?

If I release an instance of NSOperation before sending -init to it I get a segmentation fault. Reasons I think this is valid code: Apple does this in its documentation. Gnustep does it in its implementation of NSNumber, so it's fairly certain that this is in Apple's code too. (At least was.) NSObjects -init doesn't do anything, theref...

Threaded drawing on the iPhone

Apples documentation states that in general Quartz2D is thread-safe. However when drawing to an image context during a NSOperation I'm experiencing crashes (EXC_BAD_ACCESS). This is my current setup: UIGraphicsBeginImageContext(imageSize); CGContextRef context = UIGraphicsGetCurrentContext(); // drawing code UIImage *image = UIGraphic...

Queue of NSOperations and handling application exit

Hi there, I'm about to create a series of NSOperations and run them in a queue. They will all be sequential and run one at a time. These operations will fetch data from the web and create and save core data managed objects. How do I handle the situation where the application exits? As the operations run in detached threads, how can I...

Asynchronous methods in NSOperation

Hi there, I'm fetching some data from Facebook Connect (using the FBConnect Objective-C 2.0 framework) and I'm doing all that in an NSOperation. It is in an NSOperation because I have several other operations that run as well and this is one of them. The problem is that all the FBConnect calls are asynchronous. Because of this, the mai...

iPhone/Cocoa Touch - problem with multithreading (Stanford Presence 3 project)

I have been solving the Stanford free iPhone course project called Presence 3 (found on the stanford site: www.stanford.edu/class/cs193p/cgi-bin/downloads.php, which pulls data from twitter for users, which are stored in a plist. A UIActivityIndicator (spinner) is visible while the data is loading. Once the data has been loaded, a TableV...

Problems Queuing Concurrent & Non-Concurrent NSOperations

Hi there, I have an NSOperationQueue which contains 2 NSOperations and is set to perform them one after another by setting setMaxConcurrentOperationCount to 1. One of the operations is a standard non-concurrent operation (just a main method) which synchronously retrieves some data from the web (on the separate operation thread of cours...

NSOperation will not cancel NSXMLParser. Which continues to call methods on delegate causing crash

I am trying to download some XML on another thread, and parse it. I release the 'controller' then call cancelAllOperations on the NSOperationQueue. And implement method 'cancel' on NSoperation which attempts to set nSXMLParser's delegate to nil. But a second or so later the NSXMLParser is still alive and kicking and calls methods on i...

UIActivityIndicatorView with UITableView in Navigation Controller

Hello guys, I am working on a an application which is very simple a navigation controller with a table view when the user clicks a row, he is directed to the details view. However, the details view pulls data from Core Data. i am pulling a relatively large amount of data that takes about three seconds to load. I wanted to add that UIA...

NSOperation performSelectorOnMainThread crashes

Hi! I'm calling a NSOperation from a Subview of a NavigationController. MyOperation *op = [[MyOperation alloc] target:self action:@selector(didFinishOperation)]; The Operation loads some data from a server, parses it and then sends a [target performSelectorOnMainThread:action withObject:nil waitUntilDone:YES]; when the job is done...