Skip to content

Instantly share code, notes, and snippets.

@skyuplam
Created July 3, 2013 03:40
Show Gist options
  • Save skyuplam/5915281 to your computer and use it in GitHub Desktop.
Save skyuplam/5915281 to your computer and use it in GitHub Desktop.
// 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