nsoperation

NSOperation on the iPhone

偶尔善良 提交于 2019-11-26 23:44:29
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 solution here would be to describe a use-case scenario for NSOperation and how you would use it to solve your problem(s). Cocoa Is My Girlfriend has a good tutorial on the use of NSOperation and NSOperationQueue . The tutorial makes use of NSOperation to

How do I use NSOperationQueue with NSURLSession?

我是研究僧i 提交于 2019-11-26 22:30:58
问题 I'm trying to build a bulk image downloader, where images can be added to a queue on the fly to be downloaded, and I can find out the progress and when they're done downloading. Through my reading it seems like NSOperationQueue for the queue functionality and NSURLSession for the network functionality seems like my best bet, but I'm confused as to how to use the two in tandem. I know I add instances of NSOperation to the NSOperationQueue and they get queued. And it seems I create a download

Application sticks on OSSpinLockLockSlow

爷,独闯天下 提交于 2019-11-26 20:07:10
问题 Update 2: I found a workaround which is to synchronize MOC deallocating and saving. Please see the updated project. https://github.com/shuningzhou/MOCDeadLock.git Note: I made it fail more aggressively. Don't run it on a real device! Update: A sample project to demonstrate this issue. https://github.com/shuningzhou/MOCDeadLock.git XCode 6.2: Unable to reproduce. XCode 6.3: Reproducible. XCode 6.4 beta: Reproducible. ========================== The Issue =============================== Our app

iOS - How to know when NSOperationQueue finish processing a few operations?

微笑、不失礼 提交于 2019-11-26 19:35:58
问题 I need in my application to download directories and their content. So I decided to implement a NSOperationQueue and I subclassed NSOperation to implement NSURLRequest etc... The problem is I add all the operations at once and I can't figure out when all the files for one directory are downloaded in order to update the UI and enable this specific directory. Now I have to wait that all the files from all the directories are downloaded in order to update the UI. I already implemented key-value

Proper way to deal with cell reuse with background threads?

≡放荡痞女 提交于 2019-11-26 18:55:35
问题 I have a UICollectionView , but the same methods should apply to UITableViews . Each of my cells contains an image I load from disk, which is a slow operation. To mitigate this, I use an async dispatch queue. This works fine, but quickly scrolling results in these operations stacking up, such that the cell will change its image from one to another in sequence, until finally stopping at the last call. In the past, I've done a check to see if the cell was still visible, and if not I don't

Asynchronous NSURLConnection with NSOperation

孤者浪人 提交于 2019-11-26 16:04:59
问题 I want to do NSURLConnection in background mode,because it response is having much data.Forums are telling to use Apple's finite length coding to use in didEnterBackground . but I want to avoid it.instead of it I use following code through NSOperation with NSInvocation as, but it is not working. connectToServer is having NSURLConnection operation.any help please? didReceiveData , didReceiveResponse delegate methods are not called? NSOperationQueue *queue = [NSOperationQueue new];

Get notification when NSOperationQueue finishes all tasks

守給你的承諾、 提交于 2019-11-26 14:52:28
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 NSOperation s, because I don't know which one is going to be last, and [queue operations] might not be empty yet (or worse - repopulated) when notification is received. Use KVO to observe the operations property of your queue, then you can tell if your queue has completed by checking for [queue.operations count] == 0 . Somewhere in the file you're doing

Subclassing NSOperation to be concurrent and cancellable

a 夏天 提交于 2019-11-26 12:35:09
问题 I am unable to find good documentation about how to subclass NSOperation to be concurrent and also to support cancellation. I read the Apple docs, but I am unable to find an \"official\" example. Here is my source code : @synthesize isExecuting = _isExecuting; @synthesize isFinished = _isFinished; @synthesize isCancelled = _isCancelled; - (BOOL)isConcurrent { return YES; } - (void)start { /* WHY SHOULD I PUT THIS ? if (![NSThread isMainThread]) { [self performSelectorOnMainThread:@selector

Trying to Understand Asynchronous Operation Subclass

两盒软妹~` 提交于 2019-11-26 12:17:04
问题 I am trying to get started with using Operation s in a side project rather than having closure-based callbacks littered throughout my networking code to help eliminate nested calls. So I was doing some reading on the subject, and I came across this implementation: open class AsynchronousOperation: Operation { // MARK: - Properties private let stateQueue = DispatchQueue(label: \"asynchronous.operation.state\", attributes: .concurrent) private var rawState = OperationState.ready private dynamic

Can you use cancel/isCancelled with GCD/dispatch_async?

杀马特。学长 韩版系。学妹 提交于 2019-11-26 10:59:39
问题 I\'ve been wondering, can you use cancel/cancelAllOperations/.isCancelled with a thread you have launched with GCD? Currently, I just use a boolean as a flag, to cancel the background process. Let\'s say you want to do a lot of processing in the background, while keeping the UI responsive so that you can catch a cancel button (or animate something to show the processor is working). Here\'s how we do it... @interface AstoundingView : UIView { BOOL pleaseAbandonYourEfforts; blah }