.h
import <UIKit/UIKit.h>
@interface UISwitch (WithKey)
@property (nonatomic,strong)NSString *keyString;
@end
.m
import "UISwitch+WithKey.h"
import <objc/runtime.h>
@implementation UISwitch (WithKey)
static char keyStringKey;
-(NSString *)keyString
{
return objc_getAssociatedObject(self, &keyStringKey);
}
-(void)setKeyString:(NSString *)keyString
{
objc_setAssociatedObject(self, &keyStringKey, keyString, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
@end
@property (nonatomic, assign) NSInteger subRow;
pragma mark - NSIndexPath (SKSTableView)
static void *SubRowObjectKey;
@implementation NSIndexPath (SKSTableView)
@dynamic subRow;
(NSInteger)subRow
{
id subRowObj = objc_getAssociatedObject(self, SubRowObjectKey);
return [subRowObj integerValue];
}(void)setSubRow:(NSInteger)subRow
{
id subRowObj = [NSNumber numberWithInteger:subRow];
objc_setAssociatedObject(self, SubRowObjectKey, subRowObj, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}