Created
September 20, 2013 12:29
-
-
Save jmcd/6636739 to your computer and use it in GitHub Desktop.
An NSOperation that controls its own finish - useful for operations that use async code (NSConnection etc.). Override start (and call base), then call [self finish] when done.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
@interface XOp : NSOperation | |
- (void)finish; | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "XOp.h" | |
@implementation XOp { | |
BOOL _isExecuting; | |
BOOL _isFinished; | |
} | |
- (void)start { | |
[self willChangeValueForKey:@"isExecuting"]; | |
_isExecuting = YES; | |
[self didChangeValueForKey:@"isExecuting"]; | |
} | |
- (BOOL)isConcurrent { | |
return NO; | |
} | |
- (BOOL)isExecuting { | |
return _isExecuting; | |
} | |
- (BOOL)isFinished { | |
return _isFinished; | |
} | |
- (void)finish { | |
[self willChangeValueForKey:@"isExecuting"]; | |
[self willChangeValueForKey:@"isFinished"]; | |
_isExecuting = NO; | |
_isFinished = YES; | |
[self didChangeValueForKey:@"isExecuting"]; | |
[self didChangeValueForKey:@"isFinished"]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment