17 #import "NIOperations.h"
19 #import "NIDebuggingTools.h"
20 #import "NIPreprocessorMacros.h"
21 #import "NIOperations+Subclassing.h"
23 #if !defined(__has_feature) || !__has_feature(objc_arc)
24 #error "Nimbus requires ARC support."
33 _didFinishBlock = nil;
34 _didFailWithErrorBlock = nil;
35 _willFinishBlock = nil;
38 #pragma mark - Initiate delegate notification from the NSOperation
41 [
self performSelectorOnMainThread:@selector(onMainThreadOperationDidStart)
43 waitUntilDone:[NSThread isMainThread]];
47 [
self performSelectorOnMainThread:@selector(onMainThreadOperationDidFinish)
49 waitUntilDone:[NSThread isMainThread]];
52 - (void)didFailWithError:(NSError *)error {
53 self.lastError = error;
55 [
self performSelectorOnMainThread:@selector(onMainThreadOperationDidFailWithError:)
57 waitUntilDone:[NSThread isMainThread]];
61 if ([
self.
delegate respondsToSelector:
@selector(nimbusOperationWillFinish:)]) {
62 [
self.delegate nimbusOperationWillFinish:self];
66 self.willFinishBlock(
self);
70 #pragma mark - Main Thread
72 - (void)onMainThreadOperationDidStart {
74 NIDASSERT([NSThread isMainThread]);
76 if ([
self.
delegate respondsToSelector:
@selector(nimbusOperationDidStart:)]) {
77 [
self.delegate nimbusOperationDidStart:self];
81 self.didStartBlock(
self);
85 - (void)onMainThreadOperationDidFinish {
87 NIDASSERT([NSThread isMainThread]);
89 if ([
self.
delegate respondsToSelector:
@selector(nimbusOperationDidFinish:)]) {
90 [
self.delegate nimbusOperationDidFinish:self];
94 self.didFinishBlock(
self);
98 - (void)onMainThreadOperationDidFailWithError:(NSError *)error {
100 NIDASSERT([NSThread isMainThread]);
102 if ([
self.
delegate respondsToSelector:
@selector(nimbusOperationDidFail:withError:)]) {
103 [
self.delegate nimbusOperationDidFail:self withError:error];
107 self.didFailWithErrorBlock(
self, error);
NIOperationDidFailBlock didFailWithErrorBlock
The operation failed in some way and has completed.
void willFinish()
In the operation's thread, notify the delegate that the operation will finish successfully.
NIOperationBlock didStartBlock
The operation has started executing.
void didFinish()
On the main thread, notify the delegate that the operation has finished.
NIOperationBlock willFinishBlock
The operation is about to complete successfully.
A base implementation of an NSOperation that supports traditional delegation and blocks.
id< NIOperationDelegate > delegate
The delegate through which changes are notified for this operation.
void didStart()
On the main thread, notify the delegate that the operation has begun.
NIOperationBlock didFinishBlock
The operation has completed successfully.