Created
July 3, 2013 03:40
-
-
Save skyuplam/5915281 to your computer and use it in GitHub Desktop.
This file contains 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
// ReadWriter.h | |
@interface ReadWriter | |
- (id)initWithFile:(NSString *)file; | |
@end | |
@interface ReadWriter (Reader) | |
- (NSData *)readError:(NSError * __autoreleasing *)error; | |
@end | |
@interface ReadWriter (Writer) // by using informal protocols we skip not implemented warnings from the compiler | |
- (BOOL)write:(NSData *)data error:(NSError * __autoreleasing *)error; | |
@end | |
// ReadWriter.m | |
@interface ReadWriter () | |
@property (nontatomic, strong, readonly) Reader *reader; | |
@property (nontatomic, strong, readonly) Writer *writer; | |
@end | |
@implementation | |
- (id)initWithFile:(NSString *)file { | |
self = [super init]; | |
if (!self) { | |
_reader = [[Reader alloc] initWithFile:file]; | |
_writer = [[Writer alloc] initWithFile:file]; | |
} | |
return self | |
} | |
- (id)forwardingTargetForSelector:(SEL)sel { | |
if ([_reader respondsToSelector:sel] return _reader; | |
if ([_writer respondsToSelector:sel] return _writer; | |
return nil; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment