Latest0.0.4
Homepagehttps://github.com/synappsdev/SAActionBlocks
LicenseMIT
Authors

SAActionBlocks are blocks that are executed after a specified (NSTimeInterval) delay.

Examples

Say, for instance, you want to perform the following method after a delay of one second:

- (void)myGreatMethodWithValue:(id)value1 andAlternateValue:(id)value2;

You could do this using the built in performSelector:withObject:afterDelay: method.
However we want to be able to specify more than one argument.
This is made possible by using SAActionBlocks.

[SAActionBlocks performBlockAfterDelay:1.0 block:^{
    [self myGreatMethodWithValue:value1 andAlternateValue:value2];
}];

This example executes the method on the main thread after the specified delay.
However, you can also run the method on a background thread by using:

[SAActionBlocks performBlockOnUniqueBackgroundQueueAfterDelay:1.0 block:^{
    [self myGreatMethodWithValue:value1 andAlternateValue:value2];
}];

You can also specify an NSOperationQueue that you would like the method to be performed on:

[SAActionBlocks performBlockOnQueue:customQueue afterDelay:1.0 block:^{
    [self myGreatMethodWithValue:value1 andAlternateValue:value2];
}];

As these performBlock methods take a block parameter, you can run any code after a delay!

[SAActionBlocks performBlockAfterDelay:1.0 block:^{
    NSString *constantValue = @"Hello World";
    for (NSString *value in self.allValues) {
        [self myGreatMethodWithValue:value andAlternateValue:constantValue];
    }
}];
One Last Thing …

You can also run blocks of code on a Grand Central Dispatch (GCD) Queue:

[SAActionBlocks performBlockOnGCDQueue:gcdQueue afterDelay:1.0 block:^{
    [self myGreatMethodWithValue:value1 andAlternateValue:value2];
}];

And even an NSThread:

[SAActionBlocks performBlockOnThread:myThread afterDelay:1.0 block:^{
    [self myGreatMethodWithValue:value1 andAlternateValue:value2];
}];

Documentation

The documentation associated with SAActionBlocks can be viewed on the Wiki.

Donation

This code is free to use and redistribute in your apps.

If you like it you can send a small donation to either of the following addresses:

1TobyaXFetqBigGb7zRrLbMXLzUnsrrQA (BTC)

LfFBPhH5NsVTR2KqRP67RVDPPcExLZLyKQ (LTC)

Latest podspec

{
    "name": "SAActionBlocks",
    "version": "0.0.4",
    "summary": "A simple class that adds timed delay blocks to your code.",
    "homepage": "https://github.com/synappsdev/SAActionBlocks",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Toby Herbert": "[email protected]"
    },
    "source": {
        "git": "https://github.com/synappsdev/SAActionBlocks.git",
        "tag": "0.0.4"
    },
    "social_media_url": "https://twitter.com/synappsdev",
    "requires_arc": true,
    "source_files": "SAActionBlocks",
    "public_header_files": "SAActionBlocks/*.h"
}

Pin It on Pinterest

Share This