nsoperationqueue

iOS Download & Parsing Large JSON responses is causing CFData (store) leaks

微笑、不失礼 提交于 2019-12-01 14:32:53
The first time a user opens my app I need to download lots of data. I get all of this data from the server in JSON form. Depending on the user, these JSON files can be anywhere from 10kb - 30mb each, and there are 10+ of them. I have no problems doing this when the JSONs have no more than 500 or so records, but like I said some have 10,000+ records and can be up to 30mb in size. When downloading the larger JSONs, my app allocs a ton of memory, until I eventually get memory warnings and the app blows up. It seems the CFData has to be the NSMutableData that I am building in didReceiveData. As I

[NSBlockOperation addExecutionBlock:]: blocks cannot be added after the operation has started executing or finished

瘦欲@ 提交于 2019-12-01 09:21:47
I am trying to start again NSBlockOperation after completing or canceling it, but getting an error? Any one have any idea where is mistake? Thanks let imageURLs = ["http://www.planetware.com/photos-large/F/france-paris-eiffel-tower.jpg", "http://adriatic-lines.com/wp-content/uploads/2015/04/canal-of-Venice.jpg", "http://algoos.com/wp-content/uploads/2015/08/ireland-02.jpg", "http://bdo.se/wp-content/uploads/2014/01/Stockholm1.jpg"] class Downloader { class func downloadImageWithURL(url:String) -> UIImage! { let data = NSData(contentsOfURL: NSURL(string: url)!) return UIImage(data: data!) } }

block is likely to lead a retain cycle [duplicate]

五迷三道 提交于 2019-12-01 08:58:05
This question already has an answer here: Blocks retain cycle from naming convention? 1 answer I've written the following category for NSOperationBlock @implementation NSOperationQueue (Extensions) -(void)addAsynchronousOperationWithBlock:(void (^)(block))operationBlock { dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); block signal = ^ { dispatch_semaphore_signal(semaphore); }; [self addOperationWithBlock:^{ operationBlock(signal); dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); dispatch_release(semaphore); }]; } @end it seems to work properly but when I call it (as

block is likely to lead a retain cycle [duplicate]

a 夏天 提交于 2019-12-01 05:54:53
问题 This question already has an answer here : Blocks retain cycle from naming convention? (1 answer) Closed 5 years ago . I've written the following category for NSOperationBlock @implementation NSOperationQueue (Extensions) -(void)addAsynchronousOperationWithBlock:(void (^)(block))operationBlock { dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); block signal = ^ { dispatch_semaphore_signal(semaphore); }; [self addOperationWithBlock:^{ operationBlock(signal); dispatch_semaphore

Queue of NSOperations and handling application exit

筅森魡賤 提交于 2019-11-30 22:54:01
I'm about to create a series of NSOperation s 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 make the main thread wait until the current operation is "safe" to quit? There are situations where I'm happy for the threads (operations) to exit before they are complete as on further app launches the job will continue and pick up where it left off. Many thanks, Mike

How do I start an Asynchronous NSURLConnection inside an NSOperation?

China☆狼群 提交于 2019-11-30 22:24:19
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. This is a very similar question to what they asked here: How do I do an Asynchronous NSURLConnection inside an NSOperation? but the difference is that I run the connection in another class. Here is my first attempt: In my MainViewController: @property (nonatomic, strong) NSOperationQueue *requestQueue; #pragma mark - Lazy initialization - (NSOperationQueue *)requestQueue { if (!_requestQueue) { _requestQueue = [

Wait for all Operations in queue to finish before performing task

最后都变了- 提交于 2019-11-30 20:16:33
I have an Operation subclass and Operation queue with maxConcurrentOperationCount = 1. This performs my operations in a sequential order that i add them which is good but now i need to wait until all operations have finished before running another process. i was trying to use notification group but as this is run in a for loop as soon as the operations have been added to the queue the notification group fires.. How do i wait for all operations to leave the queue before running another process? for (index, _) in self.packArray.enumerated() { myGroup.enter() let myArrayOperation = ArrayOperation

NSOperationQueue vs GCD

只谈情不闲聊 提交于 2019-11-30 18:19:05
In what cases would you prefer to use NSOperationQueue over GCD? From my limited experience of these two, I take it that with NSOperationQueue you basically have control over how many concurrent operations there are. With GCD you can't do this, since you are using a queue. Except you can somehow simulate this with a multi core processor, although still I think there's no way to control it. NSOperationQueue is built on GCD as of iOS 4. Use the simplest API for the task at hand.Measure if it's a performance problem and then reevaluate if needed. dispatch_async is lower level, usually C-type

Queue of NSOperations and handling application exit

…衆ロ難τιáo~ 提交于 2019-11-30 17:46:22
问题 I'm about to create a series of NSOperation s 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 make the main thread wait until the current operation is "safe" to quit? There are situations where I'm happy for the threads (operations) to exit before they are

NSOperationQueue vs GCD

青春壹個敷衍的年華 提交于 2019-11-30 16:54:09
问题 In what cases would you prefer to use NSOperationQueue over GCD? From my limited experience of these two, I take it that with NSOperationQueue you basically have control over how many concurrent operations there are. With GCD you can't do this, since you are using a queue. Except you can somehow simulate this with a multi core processor, although still I think there's no way to control it. 回答1: NSOperationQueue is built on GCD as of iOS 4. Use the simplest API for the task at hand.Measure if