Created
October 21, 2013 22:31
-
-
Save JaviSoto/7092061 to your computer and use it in GitHub Desktop.
NSData decorator example if you're putting the bytes of an object in NSData and want to make sure ARC doesn't deallocate that object before you call -[data bytes];
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
@interface JSObjectBytesDataDecorator : NSData | |
+ (instancetype)dataDecoratorWithData:(NSData *)data holdingOnToBytesOfObject:(id)object; | |
@end |
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
@implementation JSObjectBytesDataDecorator | |
{ | |
NSData *_decoratedData; | |
id _object; | |
} | |
+ (instancetype)dataDecoratorWithData:(NSData *)data holdingOnToBytesOfObject:(id)object | |
{ | |
JSObjectBytesDataDecorator *decorator = [[self alloc] init]; | |
decorator->_decoratedData = data; | |
decorator->_object = object; | |
return decorator; | |
} | |
- (id)forwardingTargetForSelector:(SEL)aSelector | |
{ | |
return _decoratedData; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment