CocoaPods trunk is moving to be read-only. Read more on the blog, there are 19 months to go.
TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Dec 2014 |
Maintained by Toby Herbert.
SAActionBlocks are blocks that are executed after a specified (NSTimeInterval) delay.
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];
}
}];
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];
}];
The documentation associated with SAActionBlocks can be viewed on the Wiki.
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)