Created
July 27, 2016 06:04
-
-
Save verma-manish58/6a2b955774e9412e227aa764a2e73733 to your computer and use it in GitHub Desktop.
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
Then you can simply use the NSArray property defined on the UILabel just like any other pre-defined property as follows: | |
UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 150, 150)]; | |
[lbl setArrTitlesAssociativeObj:@[]]; | |
lbl.arrTitlesAssociativeObj = @[]; |
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
// | |
// NSObject+AssociatedObject.h | |
// OCLearning | |
// | |
// Created by Manish Verma on 26/07/16. | |
// Copyright © 2016 Manish Verma. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
@interface NSObject (AssociatedObject) | |
- (void)associateValue:(id)value forKey:(void*)key; | |
- (id)getAssociatedValueForKey:(void*)key; | |
@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
// | |
// NSObject+AssociatedObject.m | |
// OCLearning | |
// | |
// Created by Manish Verma on 26/07/16. | |
// Copyright © 2016 Manish Verma. All rights reserved. | |
// | |
#import "NSObject+AssociatedObject.h" | |
#import <objc/runtime.h> | |
@implementation NSObject (AssociatedObject) | |
- (void)associateValue:(id)value forKey:(void*)key { | |
objc_setAssociatedObject(self, &key, value, OBJC_ASSOCIATION_RETAIN_NONATOMIC); | |
} | |
- (id)getAssociatedValueForKey:(void*)key { | |
return objc_getAssociatedObject(self, &key); | |
} | |
@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
// | |
// UILabel+CustomLabel.h | |
// OCLearning | |
// | |
// Created by Manish Verma on 26/07/16. | |
// Copyright © 2016 Manish Verma. All rights reserved. | |
// | |
#import <UIKit/UIKit.h> | |
@interface UILabel (CustomLabel) | |
@property (nonatomic, retain) NSArray *arrTitlesAssociativeObj; | |
@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
// | |
// UILabel+CustomLabel.m | |
// OCLearning | |
// | |
// Created by Manish Verma on 26/07/16. | |
// Copyright © 2016 Manish Verma. All rights reserved. | |
// | |
#import "UILabel+CustomLabel.h" | |
#import "NSObject+AssociatedObject.h" | |
@implementation UILabel (CustomLabel) | |
- (void)setArrTitlesAssociativeObj:(NSArray *)arrTitlesAssociativeObj { | |
[self associateValue:arrTitlesAssociativeObj forKey:@selector(arrTitlesAssociativeObj)]; | |
} | |
- (NSArray*)arrTitlesAssociativeObj { | |
return [self getAssociatedValueForKey:@selector(arrTitlesAssociativeObj)]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment