Created
February 28, 2016 20:52
-
-
Save Kievkao/babec52fe2c03e5707b9 to your computer and use it in GitHub Desktop.
Proxying in Objective-C
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
| @interface ChildClass : NSObject | |
| - (NSInteger)read; | |
| @end | |
| // *.h | |
| @interface MyDecorator : NSObject | |
| + (instancetype)decoratedInstanceOf:(ChildClass *)instance; | |
| @end | |
| // *.m | |
| @interface MyDecorator() | |
| @property (nonatomic, strong) ChildClass *instance; | |
| @end | |
| @implementation MyDecorator | |
| + (instancetype)decoratedInstanceOf:(ChildClass *)instance { | |
| return [[self alloc] initWithObject:instance]; | |
| } | |
| - (instancetype)initWithObject:(ChildClass *)object { | |
| _instance = object; | |
| return self; | |
| } | |
| - (id)forwardingTargetForSelector:(SEL)aSelector { | |
| return self.instance; | |
| } | |
| - (NSInteger)read { | |
| return [self.instance read] + 1; | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment