Skip to content

Instantly share code, notes, and snippets.

@peiweichen
Created January 5, 2016 12:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peiweichen/055148fad18f87b91bea to your computer and use it in GitHub Desktop.
Save peiweichen/055148fad18f87b91bea to your computer and use it in GitHub Desktop.
Add property to PHAsset using Associated Object and Category
#import <Foundation/Foundation.h>
#import <Photos/PHAsset.h>
@interface PHAsset (Addition)
@property (nonatomic,assign) BOOL selected;
@end
#import "PHAsset+Addition.h"
#import <objc/runtime.h>
@implementation PHAsset(Addition)
-(BOOL)selected {
return [objc_getAssociatedObject(self, @selector(selected)) boolValue];;
}
-(void)setSelected:(BOOL)selected {
objc_setAssociatedObject(self, @selector(selected), @(selected), OBJC_ASSOCIATION_ASSIGN);
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment