Mac Developer Library

Developer

Foundation Framework Reference NSBlockOperation Class Reference

Options
Deployment Target:

On This Page
Language:

NSBlockOperation

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. When executing more than one block, the operation itself is considered finished only when all blocks have finished executing. More...

Inheritance


Conforms To


Import Statement


import Foundation @import Foundation;

Availability


Available in OS X v10.6 and later.
  • Creates and returns an NSBlockOperation object and adds the specified block to it.

    Declaration

    Swift

    convenience init(block block: () -> Void)

    Objective-C

    + (instancetype)blockOperationWithBlock:(void (^)(void))block

    Parameters

    block

    The block to add to the new block operation object’s list. The block should take no parameters and have no return value.

    Return Value

    A new block operation object.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.6 and later.

  • Adds the specified block to the receiver’s list of blocks to perform.

    Declaration

    Swift

    func addExecutionBlock(_ block: () -> Void)

    Objective-C

    - (void)addExecutionBlock:(void (^)(void))block

    Parameters

    block

    The block to add to the receiver’s list. The block should take no parameters and have no return value.

    Discussion

    The specified block should not make any assumptions about its execution environment.

    Calling this method while the receiver is executing or has already finished causes an NSInvalidArgumentException exception to be thrown.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.6 and later.

  • The blocks associated with the receiver. (read-only)

    Declaration

    Swift

    var executionBlocks: [AnyObject] { get }

    Objective-C

    @property(readonly, copy) NSArray *executionBlocks

    Discussion

    The blocks in this array are copies of those originally added using the addExecutionBlock: method.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.6 and later.