nsoperation

Pause NSOperation

浪尽此生 提交于 2019-12-03 09:57:20
问题 I have NSOperationQueue with some NSOperations in it ( NSInvocationOperations , in particular). This operations do some calculations and change states of UI elements accordingly (of course, via performSelectorOnMainThread:... ), often with use of animations. My UI has UINavigationViewController and some buttons for navigation to another views. So user can leave current view, while calculations / animations are still in progress. And what I need is to stop this somehow until user comes back to

Constantly growing memory allocation while fetching images over HTTP in iOS

你离开我真会死。 提交于 2019-12-03 09:04:53
问题 I am implementing an iOS App that needs to fetch a huge amount of images over HTTP. I've tried several approaches but independently what I do, Instuments shows constantly increasing memory allocations and the App crashes sooner or later when I run it on a device. There are no leaks shown by Instruments. So far I have tried the following approches: Fetch the images using a synchronous NSURLConnection within an NSOperation Fetch the images using a asynchronous NSURLConnection within an

How can I Pause a NSOperation in a NSOperationQueue?

为君一笑 提交于 2019-12-03 06:01:01
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? brush51 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 the corresponding operation queue using the setSuspended: method. Suspending a queue does not cause

Managing a bunch of NSOperation with dependencies

前提是你 提交于 2019-12-03 05:08:42
问题 I'm working on an application that create contents and send it to an existing backend. Content is a title, a picture and location. Nothing fancy. The backend is a bit complicated so here is what I have to do : Let the user take a picture, enter a title and authorize the map to use its location Generate a unique identifier for the post Create the post on the backend Upload the picture Refresh the UI I've used a couple of NSOperation subclasses to make this work but I'm not proud of my code,

Learning NSBlockOperation

前提是你 提交于 2019-12-03 02:24:04
问题 I'm a big fan of blocks, but have not used them for concurrency. After some googling, I pieced together this idea to hide everything I learned in one place. The goal is to execute a block in the background, and when it's finished, execute another block (like UIView animation)... - (NSOperation *)executeBlock:(void (^)(void))block completion:(void (^)(BOOL finished))completion { NSOperation *blockOperation = [NSBlockOperation blockOperationWithBlock:block]; NSOperation *completionOperation =

Core Data and NSOperation

…衆ロ難τιáo~ 提交于 2019-12-03 01:48:14
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 save an empty document before doing the import (otherwise the -save: fails because the document hasn't

Undoing Core Data insertions that are performed off the main thread

牧云@^-^@ 提交于 2019-12-03 01:32:53
问题 I'm working on some code that uses an NSOperation to import data. I'd like for the user to be able to undo the NSManagedObject instances that are created during the import operation. From what I can tell, it's impossible to use the NSManagedObjectContext -undoManager for any operations that are performed off of the main thread. From the Core Data Programming Guide section on Use Thread Confinement to Support Concurrency , we have these two conditions: Only objectID should be passed between

Pause NSOperation

依然范特西╮ 提交于 2019-12-03 00:31:51
I have NSOperationQueue with some NSOperations in it ( NSInvocationOperations , in particular). This operations do some calculations and change states of UI elements accordingly (of course, via performSelectorOnMainThread:... ), often with use of animations. My UI has UINavigationViewController and some buttons for navigation to another views. So user can leave current view, while calculations / animations are still in progress. And what I need is to stop this somehow until user comes back to current view. The only solution I found is to create some thread-safe boolean flag - and to check it

NSOperation blocks UI painting?

青春壹個敷衍的年華 提交于 2019-12-02 23:35:19
I'm after some advice on the use of NSOperation and drawing: I have a main thread create my NSOperation subclass, which then adds it to an NSOperationQueue . My NSOperation does some heavy processing, it is intended to loop in its main() method for several minutes, constantly processing some work, but for now I just have a while() loop with a sleep(1) inside, which is set to go around just 5 times (for testing). The main (original) thread which spawns this NSOperation is responsible for drawing to a view and updating the UI. I intended to have the NSOperation thread use a notification to tell

Constantly growing memory allocation while fetching images over HTTP in iOS

陌路散爱 提交于 2019-12-02 23:07:13
I am implementing an iOS App that needs to fetch a huge amount of images over HTTP. I've tried several approaches but independently what I do, Instuments shows constantly increasing memory allocations and the App crashes sooner or later when I run it on a device. There are no leaks shown by Instruments. So far I have tried the following approches: Fetch the images using a synchronous NSURLConnection within an NSOperation Fetch the images using a asynchronous NSURLConnection within an NSOperation Fetch the images using [NSData dataWithContentsOfURL:url] in the Main-Thread Fetch the images using