nsoperation

NSOperation and SetImage

倖福魔咒の 提交于 2019-12-05 04:23:38
问题 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

Cancel NSOperation in for loop?

♀尐吖头ヾ 提交于 2019-12-05 02:06:55
问题 I am trying to implement search on a background thread using NSOperation on iOS . I didn't want to subclass NSOperation so this is what I'm doing: [searchQueue cancelAllOperations]; NSInvocationOperation *op = [[NSInvocationOperation alloc] initWithTarget:self elector:@selector(filterContentForSearchText:) object:self.searchDisplayController.searchBar.text]; [searchQueue addOperation:op]; [op release]; The search method includes a for loop that checks whether what is being searched is in an

iOS - How to check if an NSOperation is in an NSOperationQueue?

两盒软妹~` 提交于 2019-12-04 23:22:38
问题 From the docs: An operation object can be in at most one operation queue at a time and this method throws an NSInvalidArgumentException exception if the operation is already in another queue. Similarly, this method throws an NSInvalidArgumentException exception if the operation is currently executing or has already finished executing. So how do I check if I can safely add an NSOperation into a queue? The only way I know is add the operation and then try to catch the exception if the operation

ios NSOperationQueue, operations all run when added and don't queue

会有一股神秘感。 提交于 2019-12-04 20:58:21
So, I have a group of ASINetworkQueues that currently run together resulting in a race condition when it comes to DB saves. I am trying to create an NSOperationQueue that will will queue each of these "sub queues". I currently have created an NSOperation with a main method that kicks off the "sub queue" to start it's download. My problem is that each time I add a sub queue to the main queue using "addOperation" it fires that "main" method straight away so my sub queues run concurrently. I was under the impression the main method was fired one at a time. i.e. only for the operation at the top

How to make simultaneous https requests in Swift 3

蓝咒 提交于 2019-12-04 17:29:36
I'm having problems to execute a https requests, if the request don't have any error i never get the message, this is a command line tool application and i have a plist to allow http requests, i always see the completion block. typealias escHandler = ( URLResponse?, Data? ) -> Void func getRequest(url : URL, _ handler : @escaping escHandler){ let session = URLSession.shared var request = URLRequest(url:url) request.cachePolicy = .reloadIgnoringLocalCacheData request.httpMethod = "GET" let task = session.dataTask(with: url ){ (data,response,error) in handler(response,data) } task.resume() }

How use sqlite + fdbm library with threading on the iPhone

我怕爱的太早我们不能终老 提交于 2019-12-04 11:50:18
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 pattern: @interface Db : NSObject { NSString *path; FMDatabase* theDb; BOOL isOpen; } @property (retain, nonatomic) FMDatabase *theDb; @property (retain, nonatomic) NSString *path; @property (nonatomic) BOOL isOpen; -------- static Db *currentDbSingleton = nil;

NSAutoreleasePool. When is it appropriate to create a new autorelease pool?

孤人 提交于 2019-12-04 08:36:26
On iOS/CocoaTouch I often see code that creates a new instance of NSAutoreleasePool within a method. I recently saw one within an NSOperation. What are the ground rules for setting up a new instance of NSAutoreleasePool? Why is this preferable to simply relying on the pre-existing release pool created in main.m? Thanks, Doug You can use a new autorelease pool whenever you want, but it is not always beneficial. It is required whenever you start a new thread or objects autoreleased in that thread will be leaked. It is also common to create new autorelease pools in a method where you create and

iOS App Architecture with NSOperations

笑着哭i 提交于 2019-12-04 08:17:02
问题 Two month ago I started to write a new iPhone Application and for this reason I created a generic RESTFul web service, which allows me to have a lot of these necessary features like user authentication, user profiles, a friendship system, media processing, a messaging system and so on. In my mind there are several use cases to reuse this webservice for future iPhone applications. With this state of mind, I decided to write a static library for this application (and all future apps) that

Pass data from NSOperation to next NSOperation

╄→尐↘猪︶ㄣ 提交于 2019-12-04 07:46:24
Is it possible to pass data from an NSOperation up the dependency chain to be used by the next NSOperation? Thanks Chris 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 automatically carried forward an NSDictionary of data from one operation to the next. 来源: https://stackoverflow.com

Can I cancel a Block added to an NSOperationQueue with addOperationWithBlock:?

淺唱寂寞╮ 提交于 2019-12-04 03:17:52
问题 I've read many many articles which say "BLOCKS ARE THE FUTURE!!!". I'm wondering if it relates to running operations in the background. For example, I have a table view which has images that will come from the web. Right now I can get them using +[NSOperationQueue addOperationWithBlock:] . An operation gets sent to the queue when the cell becomes visible. But is there a way to cancel it once the cell gets scrolled off the screen? Or is the only way to do it to subclass NSOperation ? Using