The NSBlockOperation class is a concrete subclass of NSOperation that manages the concurrent execution of one or more blocks. You can use this object to execute several blocks at once without having to create separate operation objects for each.
Questions tagged [nsblockoperation]
42 questions
76
votes
10 answers
How do I create a NSTimer on a background thread?
I have a task that needs to be performed every 1 second. Currently I have an NSTimer firing repeatedly every 1 sec. How do I have the timer fire in a background thread (non UI-thread)?
I could have the NSTimer fire on the main thread then use…

AWF4vk
- 5,810
- 3
- 37
- 70
55
votes
3 answers
NSURLSession with NSBlockOperation and queues
I have an app that currently uses NSURLConnection for the vast majority of its networking. I would like to move to NSURLSession because Apple tells me that is the way to go.
My app just uses the synchronous version of NSURLConnection by way of the +…

Erik Allen
- 1,841
- 2
- 20
- 36
20
votes
3 answers
Learning NSBlockOperation
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…

danh
- 62,181
- 10
- 95
- 136
9
votes
2 answers
Timer in another thread in Objective - C
I have to define method which should be invoked periodically with some time interval. I need to invoke it in another thread (NOT main thread), because this method is used to get information from external API and sync data in core data.
How do I…

user2375706
- 705
- 2
- 8
- 14
6
votes
1 answer
NSBlockOperation, NSOperationQueue and Blocks
I have to sync a bunch of information from my RestAPI. I must do 6 RestAPI calls to complete work. I designed API calls with Blocks, and return NSError if there is any.
3 of these calls should to execute nested because the first call gives…

dpizzuto
- 412
- 1
- 5
- 14
5
votes
1 answer
Syntax/formatting when nesting objective-c blocks
I'm nesting blocks, and it looks UGGGGLY. Is there a way to write this less ugly? Mostly looking for syntax suggestions, rather than structural, but I'll accept either.
My block factory method,
-(NSImage *(^)(CGFloat size, BOOL preview))resizeBlock…

Kenny Winker
- 11,919
- 7
- 56
- 78
4
votes
3 answers
NSBlockOperation and NSAutoreleasePool
Normally when you create an NSOperation subclass you are responsible for creating and releasing an NSAutoreleasePool in the -main method.
When you use an NSBlockOperation, do you need to create an autorelease pool in the block?

Adam Ernst
- 52,440
- 18
- 59
- 71
4
votes
1 answer
Granularity status of an NSBlockOperation
I have extended NSOperationQueue to allow adding NSBlockOperation with a specific NSString as identifier.
The identifier value is held in a NSMutableArray serving as a registry. This is how I implement the registry.
-(void)addOperation:(NSOperation…

Leonardo
- 9,607
- 17
- 49
- 89
3
votes
2 answers
Understanding NSBlockOperation
I'm getting into NSBlockOperation and I have some questions.
Notably, the documentation for addExecutionBlock says:
Discussion
The specified block should not make any assumptions about
its execution environment.
Calling this method while the…

Łukasz Szpyrka
- 687
- 1
- 6
- 24
3
votes
1 answer
NSOperationQueue's addOperation: operation is finished and cannot be enqueued?
Note:
This is merely a proof-of-concept.
The real background task will be to continuously request 'HTTP Get' of raw data and to display it via main thread; on demand.
Scenario:
1) Toggle a background task (loop) on demand.
2) Background task…

Frederick C. Lee
- 9,019
- 17
- 64
- 105
2
votes
0 answers
How to fix memory leak in NSFetchedResultsController controllerDidChangeContent
Problem:
I'm getting memory leaks in the function controllerDidChangeContent when I profile my app. Instruments is telling me that the leak should be in the line self.collectionView?.performBatchUpdates({ [unowned self] in. But how can there be a…

Hans Bondoka
- 437
- 1
- 4
- 14
2
votes
0 answers
The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation
import UIKit
var bOpertation = BlockOperation {
print("this is a operation 1")
}
bOpertation.addExecutionBlock {
print("this is a operation 2")
}
bOpertation.addExecutionBlock {
print("this is a operation…

Rnthking
- 35
- 5
2
votes
1 answer
NSBlockOperation is not waiting on dependency before executing
I am learning NSOperations & NSOperationQueue.
I have a set of NSBlockOperation: "UPLOAD" & "DELETE". Delete MUST wait for Upload to finish before executing.
What I would like to happen is for one operation set to complete before moving on to the…

user-44651
- 3,924
- 6
- 41
- 87
2
votes
2 answers
NSBlockOperation or NSOperation with ALAsset Block to display photo-library images using ALAsset URL
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…

Shamsudheen TK
- 30,739
- 9
- 69
- 102
2
votes
1 answer
NSBlockOperation leaks ARC
I'm having troubles referring to the ´NSBlockOperation´ inside the block itself. I need to check if the operation was cancelled and it seems that any access to the ´searchOperation´ just leaks when running in an ARC-enabled project.
This code, which…

Tomas Camin
- 9,996
- 2
- 43
- 62