forked from veritech/CSSApply
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathNSObject+CSS.m
73 lines (57 loc) · 1.62 KB
/
NSObject+CSS.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//
// NSObject+CSS.m
// CSSSample
//
// Created by Jonathan Dalrymple on 16/07/2011.
// Copyright 2011 Float:Right Ltd. All rights reserved.
//
#import "NSObject+CSS.h"
#import <objc/runtime.h>
static const char* kUIViewIDNameKey = "UIViewCSSIDNameKey";
static const char* kUIViewClassNameKey = "UIViewCSSClassNameKey";
static const char* kUIViewCSSSelectorKey = "UIViewCSSSelectorKey";
@implementation NSObject (CSS)
@dynamic CSSID, CSSClassNames, CSSSelector;
#pragma mark - ID & Class names
/**
* Set class names
* @param a NSSet
*/
-(void) setCSSClassNames:(NSSet*) aClassName{
objc_setAssociatedObject(self, &kUIViewClassNameKey, aClassName, OBJC_ASSOCIATION_COPY_NONATOMIC);
}
/**
* Class names
*
* @return NSSet
*/
-(NSSet*) CSSClassNames{
return objc_getAssociatedObject(self, &kUIViewClassNameKey);
}
/**
* set the view's id
* @param an id name
*/
-(void) setCSSID:(NSString*) anIDName{
objc_setAssociatedObject(self, &kUIViewIDNameKey, anIDName, OBJC_ASSOCIATION_COPY_NONATOMIC );
}
/**
* Get the view's id name
* @return an id name
*/
-(NSString*) CSSID{
return (NSString*) objc_getAssociatedObject(self, &kUIViewIDNameKey);
}
-(CSSSelector*)CSSSelector {
CSSSelector *selector = (CSSSelector*) objc_getAssociatedObject(self, &kUIViewCSSSelectorKey);
if (!selector)
{
selector = [[CSSSelector alloc] initWithClassName:NSStringFromClass([self class])
classNames:[self CSSClassNames]
classID:[self CSSID]
];
objc_setAssociatedObject(self, &kUIViewCSSSelectorKey, selector, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
return selector;
}
@end