TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Mar 2016 |
Maintained by Gabriel Massana.
Wrapper project to simplify NSOperation and NSOperationQueue.
platform :ios, '8.0'
pod 'CoreOperation', '~> 1.0'
Then, run the following command:
$ pod install
Drag into your project the folder /CoreOperation-iOS
. That's all.
// AppDelegate.m
NSString *const kCOMLocalOperationQueueTypeIdentifier = @"kCOMLocalOperationQueueTypeIdentifier";
#pragma mark - OperationQueues
- (void)registerOperationQueues
{
//Local Background
NSOperationQueue *localOperationQueue = [[NSOperationQueue alloc] init];
localOperationQueue.qualityOfService = NSQualityOfServiceBackground;
localOperationQueue.maxConcurrentOperationCount = 1;
[[COMOperationQueueManager sharedInstance] registerOperationQueue:localOperationQueue
operationQueueIdentifier:kCOMLocalOperationQueueTypeIdentifier];
}
// COMExampleOperation.h
@interface COMExampleOperation : COMOperation
- (instancetype)initWithValue:(NSInteger)value;
@end
// COMExampleOperation.m
@interface COMExampleOperation ()
@property (nonatomic, assign) NSInteger value;
@end
@implementation COMExampleOperation
@synthesize identifier = _identifier;
#pragma mark - Init
- (instancetype)initWithValue:(NSInteger)value
{
self = [super init];
if (self)
{
self.value = value;
}
return self;
}
#pragma mark - Identifier
- (NSString *)identifier
{
if (!_identifier)
{
_identifier = [NSString stringWithFormat:@"COMExampleOperation-%@", @(self.value)];
}
return _identifier;
}
#pragma mark - Start
- (void)start
{
[super start];
srand((unsigned)time(0));
NSInteger mod = self.value;
NSInteger random = rand();
NSInteger result = random % mod;
[self didSucceedWithResult:@(result)];
}
#pragma mark - Cancel
- (void)cancel
{
[super cancel];
[self didSucceedWithResult:nil];
}
- (void)operationExample
{
COMExampleOperation *operation = [[COMExampleOperation alloc] initWithValue:15];
operation.operationQueueIdentifier = kCOMLocalOperationQueueTypeIdentifier;
operation.onSuccess = ^(id result)
{
NSLog(@"%@", result);
};
[[COMOperationQueueManager sharedInstance] addOperation:operation];
}
ButtonBackgroundColor-iOS is released under the MIT license. Please see the file called LICENSE.
$ git tag -a 1.1.0 -m 'Version 1.1.0'
$ git push --tags
Gabriel Massana
Please open a new Issue here if you run into a problem specific to CoreOperation-iOS, have a feature request, or want to share a comment.