nsoperationqueue

NSOperationQueue not working in IOS5

假装没事ソ 提交于 2019-12-03 08:11:25
I have a project which downloads images in background using NSOperationQueue . It was working until now on devices with IOS 4.3. However if I build the app with base sdk 4.3 or with 5 and run the app on device with IOS5, the app crashes. When app is launched, it adds NSOperation objects into queue for downloading the images. If in between I press back button, I cancel the NSOperation and it crashes and displays following trace on console: #0 0x004727b7 in ____NSOQSchedule_block_invoke_0 () #1 0x026a5618 in _dispatch_call_block_and_release () #2 0x026a7a10 in _dispatch_worker_thread2 () #3

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

NSOperationQueue mainQueue vs performSelectorOnMainThread?

左心房为你撑大大i 提交于 2019-12-03 05:40:17
问题 What's the difference between this: [[NSOperationQueue mainQueue] addOperationWithBlock:^{ [self doSomthing:object]; }]; and this: [self performSelectorOnMainThread:@selector(doSomething:) withObject:object waitUntilDone:NO] 回答1: [self performSelectorOnMainThread:@selector(doSomething:) withObject:object waitUntilDone:NO] Will perform the selector right when it is called. This is what you have to use if you want to affect the UI from a background thread. If you say YES to waitUntilDone it

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,

Which is the best of GCD, NSThread or NSOperationQueue? [closed]

。_饼干妹妹 提交于 2019-12-03 03:59:05
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . What's the best way of multithreading in iOS as we have three options GCD, NSThread , and NSOperationQueue ? I am confused in which

GCD, NSOperationQueue, or create a thread manually?

天涯浪子 提交于 2019-12-03 03:45:16
When you use threads, do you have any preferences? In general rule, to use any of these techniques : create a new thread manually and use the run loop use NSOperationQueue or use Grand Central Dispatch and the C version with dispatch_queue? Does NSOperationQueue simplify everything, and thus is better to be used when we need to create an asynchronous function? I'm lazy, so my philosophy is to pick the simplest solution that does everything I need it to. (I like to think this is the "lazy" espoused by Larry Wall but sometimes I wonder.) So my order of preference would be: Asynchronous method

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 =

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

OperationQueue.main vs DispatchQueue.main

主宰稳场 提交于 2019-12-02 22:12:06
When you need to perform something on the main thread in the completion block of a networking task or an operation, which of these ways to get it would be the most appropriate and why?: OperationQueue.main.addOperation DispatchQueue.main.async MrMage For details on the differences between the two types of queue, see Lion's answer. Both approaches will work. However, NSOperation is mostly needed when more advanced scheduling (including dependencies , canceling , etc.) is required. So in this case, a simple DispatchQueue.main.async { /* do work */ } will be just fine. That would be equivalent to