Declared in NSObject+BMKitAdditions.h

Overview

BMKit related additions to the NSObject class.

Tasks

Other Methods

Executing Blocks

Sending Messages

Class Methods

cancelPreviousPerformRequestsWithTarget:block:

Cancels perform requests previously registered with performBlock:afterDelay:.

+ (void)cancelPreviousPerformRequestsWithTarget:(id)aTarget block:(BMTargetBlock)aBlock

Parameters

aTarget

The target for requests previously registered with the performBlock:afterDelay: instance method.

aBlock

The heap-allocated copy of the block for requests previously registered with the performBlock:afterDelay: instance method.

Discussion

All perform requests are canceled that have the same target as aTarget and block as aBlock.

Important: aBlock must refer to the heap-allocated copy of the block, which was passed to performBlock:afterDelay:. If unsure, just pass the value returned from performBlock:afterDelay: as aBlock.

Declared In

NSObject+BMKitAdditions.h

Instance Methods

associatedObjectForKey:

Returns the object associated with a specified key.

- (id)associatedObjectForKey:(BMAssociationKey)aKey

Parameters

aKey

An association key, an arbitrary pointer.

Return Value

The object associated with aKey, or nil if no object is associated with the key.

Declared In

NSObject+BMKitAdditions.h

performBlock:afterDelay:

Executes a block on the current thread using the default mode after a delay.

- (BMTargetBlock)performBlock:(BMTargetBlock)aBlock afterDelay:(NSTimeInterval)delay

Parameters

aBlock

The block to invoke.

delay

The minimum time before which the message is sent. Specifying a delay of 0 does not necessarily cause the block to be performed immediately. The block is still queued on the thread’s run loop and performed as soon as possible.

Return Value

A copy of the aBlock, which can be used to cancel the perform request using the cancelPreviousPerformRequestsWithTarget:block: class method.

Discussion

This method takes a copy of aBlock and schedules it for invocation after delay seconds using the performSelector:withObject:afterDelay: instance method of the NSObject class.

This method retains the receiver and keeps a heap-allocated copy of the aBlock parameter until after the block is performed.

Declared In

NSObject+BMKitAdditions.h

performBlock:afterDelay:inModes:

Executes a block on the current thread using the specified modes after a delay.

- (BMTargetBlock)performBlock:(BMTargetBlock)aBlock afterDelay:(NSTimeInterval)delay inModes:(NSArray *)modes

Parameters

aBlock

The block to execute.

delay

The minimum time before which the message is sent. Specifying a delay of 0 does not necessarily cause the block to be performed immediately. The block is still queued on the thread’s run loop and performed as soon as possible.

modes

An array of strings that identify the modes to associate with the timer that performs the selector. This array must contain at least one string. If you specify nil or an empty array for this parameter, this method returns without performing the specified block.

Return Value

A copy of the aBlock, which can be used to cancel the perform request using the cancelPreviousPerformRequestsWithTarget:block: class method.

Discussion

This method takes a copy of aBlock and schedules it for invocation in the specified modes after delay seconds using the performSelector:withObject:afterDelay:inModes: instance method of the NSObject class.

This method retains the receiver and keeps a heap-allocated copy of the aBlock parameter until after the block is performed.

Declared In

NSObject+BMKitAdditions.h

performBlock:onQueue:waitUntilDone:

Executes a block on the receiver on a given dispatch queue.

- (void)performBlock:(BMTargetBlock)aBlock onQueue:(dispatch_queue_t)aQueue waitUntilDone:(BOOL)wait

Parameters

aBlock

The block to execute.

aQueue

The dispatch queue on which to execute aBlock.

wait

A Boolean that specifies whether the current thread blocks until after the specified block is dispatched on the receiver on the specified queue. Specify YES to block this thread; otherwise, specify NO to have this method return immediately on the current thread. Be careful not to introduce deadlocks when specifying YES here.

Discussion

You can use this method to schedule a block for execution on aQueue, optionally waiting for the execution to finish.

This method retains the receiver, the aBlock parameter (or a heap-allocated copy of it) and the aQueue parameter until after the block is performed.

Declared In

NSObject+BMKitAdditions.h

performBlock:onThread:waitUntilDone:

Executes a block on the receiver on the specified thread using the default mode.

- (void)performBlock:(BMTargetBlock)aBlock onThread:(NSThread *)aThread waitUntilDone:(BOOL)wait

Parameters

aBlock

The block to execute.

aThread

The thread on which to execute aBlock.

wait

A Boolean that specifies whether the current thread blocks until after the specified block is performed on the receiver on the specified thread. Specify YES to block this thread; otherwise, specify NO to have this method return immediately. If the current thread and target thread are the same, and you specify YES for this parameter, the block is performed immediately on the current thread. If you specify NO, this method queues the message on the thread’s run loop and returns, just like it does for other threads. The current thread must then dequeue and process the message when it has an opportunity to do so.

Discussion

This method schedules a block for execution on aThread in the default mode using the performSelector:onThread:withObject:waitUntilDone: instance method of the NSObject class.

This method retains the receiver and the aBlock parameter (or a heap-allocated copy of it) until after the block is performed.

Declared In

NSObject+BMKitAdditions.h

performBlock:onThread:waitUntilDone:modes:

Executes a block on the receiver on the specified thread using the specified modes.

- (void)performBlock:(BMTargetBlock)aBlock onThread:(NSThread *)aThread waitUntilDone:(BOOL)wait modes:(NSArray *)modes

Parameters

aBlock

The block to execute.

aThread

The thread on which to execute aBlock.

wait

A Boolean that specifies whether the current thread blocks until after the specified block is performed on the receiver on the specified thread. Specify YES to block this thread; otherwise, specify NO to have this method return immediately. If the current thread and target thread are the same, and you specify YES for this parameter, the block is performed immediately on the current thread. If you specify NO, this method queues the message on the thread’s run loop and returns, just like it does for other threads. The current thread must then dequeue and process the message when it has an opportunity to do so.

modes

An array of strings that identify the modes to associate with the timer that performs the selector. This array must contain at least one string. If you specify nil or an empty array for this parameter, this method returns without performing the specified block.

Discussion

This method schedules a block for execution on aThread in the specified modes using the performSelector:onThread:withObject:waitUntilDone:modes: instance method of the NSObject class.

This method retains the receiver and the aBlock parameter (or a heap-allocated copy of it) until after the block is performed.

Declared In

NSObject+BMKitAdditions.h

performBlockInBackground:

Executes a block on the receiver on a new background thread.

- (void)performBlockInBackground:(BMTargetBlock)aBlock

Parameters

aBlock

The block to execute.

Discussion

This method takes a copy of aBlock and schedules it for background execution in a new background using the performSelectorInBackground:withObject: instance method of the NSObject class. This method also sets up an autorelease pool for the new background, so in contrast to the performSelectorInBackground:withObject: instance method, you do not need to set up an autorelease pool yourself.

This method retains the receiver and keeps a heap-allocated copy of the aBlock parameter until after the block is performed.

Declared In

NSObject+BMKitAdditions.h

performBlockOnMainThread:waitUntilDone:

Executes a block on the receiver on the main thread using the default mode.

- (void)performBlockOnMainThread:(BMTargetBlock)aBlock waitUntilDone:(BOOL)wait

Parameters

aBlock

The block to execute.

wait

A Boolean that specifies whether the current thread blocks until after the specified block is performed on the receiver on the main thread. Specify YES to block this thread; otherwise, specify NO to have this method return immediately. If the current thread is also the main thread, and you specify YES for this parameter, the block is performed immediately.

Discussion

This method schedules a block for invocation on the main thread in the default mode using the performSelectorOnMainThread:withObject:waitUntilDone: instance method of the NSObject class.

This method retains the receiver and the aBlock parameter (or a heap-allocated copy of it) until after the block is performed.

Declared In

NSObject+BMKitAdditions.h

performBlockOnMainThread:waitUntilDone:modes:

Executes a block on the receiver on the main thread using the specified modes.

- (void)performBlockOnMainThread:(BMTargetBlock)aBlock waitUntilDone:(BOOL)wait modes:(NSArray *)modes

Parameters

aBlock

The block to execute.

wait

A Boolean that specifies whether the current thread blocks until after the specified block is performed on the receiver on the main thread. Specify YES to block this thread; otherwise, specify NO to have this method return immediately. If the current thread is also the main thread, and you specify YES for this parameter, the block is performed immediately.

modes

An array of strings that identify the modes to associate with the timer that performs the selector. This array must contain at least one string. If you specify nil or an empty array for this parameter, this method returns without performing the specified block.

Discussion

This method schedules a block for invocation on the main thread in the specified modes using the performSelectorOnMainThread:withObject:waitUntilDone:modes: instance method of the NSObject class.

This method retains the receiver and the aBlock parameter (or a heap-allocated copy of it) until after the block is performed.

Declared In

NSObject+BMKitAdditions.h

performSelector:onQueue:withObject:waitUntilDone:

Invokes a method of the receiver on the specified dispatch queue.

- (void)performSelector:(SEL)aSelector onQueue:(dispatch_queue_t)aQueue withObject:(id)anObject waitUntilDone:(BOOL)wait

Parameters

aSelector

A selector that identifies the method to invoke. The method should not have a significant return value and should take a single argument of type id, or no arguments.

aQueue

The dispatch queue on which to execute aSelector.

anObject

The argument to pass to the method when it is invoked. Pass nil if the method does not take an argument.

wait

A Boolean that specifies whether the current thread blocks until after the specified selector is dispatched on the receiver on the specified queue. Specify YES to block this thread; otherwise, specify NO to have this method return immediately on the current thread. Be careful not to introduce deadlocks when specifying YES here.

Discussion

You can use this method to deliver messages to other queues in your application. The message in this case is a method of the current object that you want to execute on the target queue.

This method retains the receiver, as well as the anObject and the aQueue parameters until after the selector is performed.

Declared In

NSObject+BMKitAdditions.h

removeAssociatedObjects

Removes all associated objects of the target.

- (void)removeAssociatedObjects

Declared In

NSObject+BMKitAdditions.h

setAssociatedObject:forKey:

Associates an object with a specified key on the target.

- (void)setAssociatedObject:(id)anObject forKey:(BMAssociationKey)aKey

Parameters

anObject

The object to associate with the key. Pass nil to clear the association for aKey.

aKey

An association key, an arbitrary pointer.

Discussion

The effect of sending this message is similar to sending the setAssociatedObject:forKey:policy: message, passing BMAssociationNonatomicRetainPolicy as policy.

Declared In

NSObject+BMKitAdditions.h

setAssociatedObject:forKey:policy:

Associates an object with a specified key on the target using a specified association policy.

- (void)setAssociatedObject:(id)anObject forKey:(BMAssociationKey)aKey policy:(BMAssociationPolicy)policy

Parameters

anObject

The object to associate with the key. Pass nil to clear the association for aKey.

aKey

An association key, an arbitrary pointer.

policy

The policy for associating anObject with aKey on the target.

Discussion

Right now the following association policies are supported:

  • BMAssociationAssignPolicy Specifies a weak reference to the associated object.
  • BMAssociationAtomicRetainPolicy Specifies a strong reference to the associated object, and that the association is made atomically.
  • BMAssociationAtomicCopyPolicy Specifies that the associated object is copied, and that the association is made atomically.
  • BMAssociationNonatomicRetainPolicy Specifies a strong reference to the associated object, and that the association is not made atomically.
  • BMAssociationNonatomicCopyPolicy Specifies that the associated object is copied, and that the association is not made atomically.

Declared In

NSObject+BMKitAdditions.h