nsoperationqueue

NSFetchedResultsController doesn't show updates from a different context

醉酒当歌 提交于 2019-11-29 00:45:30
问题 I have an NSFetchedResultsController and a few operations updates managed objects on separate threads via NSOperationQueue . The FRC (with its predicate) looks like this: - (NSFetchedResultsController*)fetchedResultsController { if(fetchedResultsController) return fetchedResultsController; NSManagedObjectContext* mainContext = [self managedObjectContext]; NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; [fetchRequest setEntity:[NSEntityDescription entityForName:@"Check"

NSOperation wait until asynchronous block executes

ⅰ亾dé卋堺 提交于 2019-11-28 23:22:48
i need to put asynchronous operations into an operation queue, however, they need to execute on after the other self.operationQueue = [NSOperationQueue new]; self.operationQueue.maxConcurrentOperationCount = 1; [self.operationQueue addOperationWithBlock:^{ // this is asynchronous [peripheral1 connectWithCompletion:^(NSError *error) { }]; }]; [self.operationQueue addOperationWithBlock:^{ // this is asynchronous [peripheral2 connectWithCompletion:^(NSError *error) { }]; }]; the problem is, since peripheralN connectWithCompletion is asynchronous, the operation in queue is ended and the next is

how to cancel out of operation created with addOperationWithBlock?

北城余情 提交于 2019-11-28 23:16:49
I'm using NSOperationQueue's addOperationWithBlock. From within the block, how do I check to see if I'm supposed to cancel the operation? Or access any NSOperation properties/methods? [myOperationQueue addOperationWithBlock: ^{ while ( /* long running loop */ ) { // how to determine here if I need to cancel? // for that matter, access any NSOperation properties/methods? } }]; Is the better way to do this to use a NSBlockOperation? A better solution might be to use NSBlockOperation and add that to the queue instead of a raw block. You could do something like: __block NSBlockOperation *operation

NSAttributedString initWithData and NSHTMLTextDocumentType crash if not on main thread

不羁的心 提交于 2019-11-28 20:52:19
calling NSAttributedString * as = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUTF8StringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding)} documentAttributes:nil error:nil]; on other than main thread, results in a crash 1 0x194b861fc <redacted> 2 0x19801d31c <redacted> 3 0x198010eb4 _os_once 4 0x19801aa2c pthread_once 5 0x195a0858c <redacted> 6 0x195a07c78 WebKitInitialize 7 0x18bb38918 <redacted> 8 0x10020cdf0 _dispatch_client_callout 9 0x10020dcfc dispatch_once_f 10

NSOperation - Forcing an operation to wait others dynamically

拜拜、爱过 提交于 2019-11-28 16:33:13
I am trying to implement an operation queue and I have the following scenario: NSOperation A NSOperation B NSOperation C NSOperation D NSOperationQueue queue I start adding A to queue . During the execution of A I need to get some data from B and I can't continue with A until B returns what I need. The same situation will occur for B depending on C and for C depending on D . To manage this, at each NSOperation I have this code: NSOperation *operation; //This can be A, B, C, D or any other NSOperation [self setQueuePriority:NSOperationQueuePriorityVeryLow]; //Set the current NSOperation with

(iOS) dispatch_async() vs. NSOperationQueue

我们两清 提交于 2019-11-28 15:28:27
I learned iOS programming thanks to Stanford's CS193p course (on iTunes U) as well as the iOS programming book from Big Nerd Ranch. In both of those, they recommend using dispatch_async() , dispatch_get_main_queue() , etc. to handle threading and concurrent operations. However, at WWDC 2012's session on building concurrent UI, the speaker recommended the use of NSOperationQueue . What are the differences between dispatch_*() and NSOperationQueue , and is there any reason (technical, performance, stylistic, or otherwise) that I should use one over the other? Is NSOperationQueue just an

Do NSOperations and their completionBlocks run concurrently?

[亡魂溺海] 提交于 2019-11-28 12:31:32
I've got a bunch of NSOperations added to a NSOperationQueue . The operation queue has the maxConcurrentOperationCount set to 1, so that the NSOperations run one after the other. Now, in the completionBlock of a NSOperation I want to cancel all pending NSOperations by calling cancelAllOperations on the NSOperationQueue . Is it safe to do this? Can I be sure that the start -method of the next operation is called only after the completionBlock of the previous operation has been fully executed? Or do the completionBlock of the previous operation and the task of the current operation run

NSBlockOperation or NSOperation with ALAsset Block to display photo-library images using ALAsset URL

半城伤御伤魂 提交于 2019-11-28 11:46:46
I am asking this question regarding my questions Display photolibrary images in an effectual way iPhone and Highly efficient UITableView "cellForRowIndexPath" method to bind the PhotoLibrary images . So I would like to request that answers are not duplicated to this one without reading the below details :) Let's come to the issue, I have researched detailed about my above mentioned issue, and I have found the document about operation queues from here . So I have created one sample application to display seven photo-library images using operation queues through ALAsset blocks. Here are the

Default value of maxConcurrentOperationCount for NSOperationQueue

十年热恋 提交于 2019-11-27 23:28:14
As the title suggests, what is the default value of the maxConcurrentOperationCount for NSOperationQueue? Is it set to a value of 1? From the documentation , The maximum number of concurrent operations set explicitly on the receiver using the setMaxConcurrentOperationCount: method. If no value has been explicitly set, this method returns NSOperationQueueDefaultMaxConcurrentOperationCount by default . So it is NSOperationQueueDefaultMaxConcurrentOperationCount . If this is set, it will choose an appropriate value based on the number of available processors and other relevant factors. This is

NSOperation wait until asynchronous block executes

南笙酒味 提交于 2019-11-27 21:13:30
问题 i need to put asynchronous operations into an operation queue, however, they need to execute on after the other self.operationQueue = [NSOperationQueue new]; self.operationQueue.maxConcurrentOperationCount = 1; [self.operationQueue addOperationWithBlock:^{ // this is asynchronous [peripheral1 connectWithCompletion:^(NSError *error) { }]; }]; [self.operationQueue addOperationWithBlock:^{ // this is asynchronous [peripheral2 connectWithCompletion:^(NSError *error) { }]; }]; the problem is,