|
13 | 13 | #import "MJProperty.h" |
14 | 14 | #import "MJFoundation.h" |
15 | 15 | #import <objc/runtime.h> |
16 | | -#import "MJDictionaryCache.h" |
17 | 16 |
|
18 | 17 | #pragma clang diagnostic push |
19 | 18 | #pragma clang diagnostic ignored "-Wundeclared-selector" |
20 | 19 | #pragma clang diagnostic ignored "-Warc-performSelector-leaks" |
21 | 20 |
|
22 | | -@implementation NSObject (Property) |
23 | | - |
24 | 21 | static const char MJReplacedKeyFromPropertyNameKey = '\0'; |
25 | 22 | static const char MJReplacedKeyFromPropertyName121Key = '\0'; |
26 | 23 | static const char MJNewValueFromOldValueKey = '\0'; |
27 | 24 | static const char MJObjectClassInArrayKey = '\0'; |
28 | 25 |
|
29 | 26 | static const char MJCachedPropertiesKey = '\0'; |
30 | 27 |
|
| 28 | +@implementation NSObject (Property) |
| 29 | + |
| 30 | +static NSMutableDictionary *replacedKeyFromPropertyNameDict_; |
| 31 | +static NSMutableDictionary *replacedKeyFromPropertyName121Dict_; |
| 32 | +static NSMutableDictionary *newValueFromOldValueDict_; |
| 33 | +static NSMutableDictionary *objectClassInArrayDict_; |
| 34 | +static NSMutableDictionary *cachedPropertiesDict_; |
| 35 | + |
| 36 | ++ (void)load |
| 37 | +{ |
| 38 | + replacedKeyFromPropertyNameDict_ = [NSMutableDictionary dictionary]; |
| 39 | + replacedKeyFromPropertyName121Dict_ = [NSMutableDictionary dictionary]; |
| 40 | + newValueFromOldValueDict_ = [NSMutableDictionary dictionary]; |
| 41 | + objectClassInArrayDict_ = [NSMutableDictionary dictionary]; |
| 42 | + cachedPropertiesDict_ = [NSMutableDictionary dictionary]; |
| 43 | +} |
| 44 | + |
| 45 | ++ (NSMutableDictionary *)dictForKey:(const void *)key |
| 46 | +{ |
| 47 | + if (key == &MJReplacedKeyFromPropertyNameKey) return replacedKeyFromPropertyNameDict_; |
| 48 | + if (key == &MJReplacedKeyFromPropertyName121Key) return replacedKeyFromPropertyName121Dict_; |
| 49 | + if (key == &MJNewValueFromOldValueKey) return newValueFromOldValueDict_; |
| 50 | + if (key == &MJObjectClassInArrayKey) return objectClassInArrayDict_; |
| 51 | + if (key == &MJCachedPropertiesKey) return cachedPropertiesDict_; |
| 52 | + return nil; |
| 53 | +} |
| 54 | + |
31 | 55 | #pragma mark - --私有方法-- |
32 | 56 | + (NSString *)propertyKey:(NSString *)propertyName |
33 | 57 | { |
@@ -124,7 +148,7 @@ + (void)mj_enumerateProperties:(MJPropertiesEnumeration)enumeration |
124 | 148 | #pragma mark - 公共方法 |
125 | 149 | + (NSMutableArray *)properties |
126 | 150 | { |
127 | | - NSMutableArray *cachedProperties = [MJDictionaryCache objectForKey:NSStringFromClass(self) forDictId:&MJCachedPropertiesKey]; |
| 151 | + NSMutableArray *cachedProperties = [self dictForKey:&MJCachedPropertiesKey][NSStringFromClass(self)]; |
128 | 152 |
|
129 | 153 | if (cachedProperties == nil) { |
130 | 154 | cachedProperties = [NSMutableArray array]; |
@@ -154,7 +178,7 @@ + (NSMutableArray *)properties |
154 | 178 | free(properties); |
155 | 179 | }]; |
156 | 180 |
|
157 | | - [MJDictionaryCache setObject:cachedProperties forKey:NSStringFromClass(self) forDictId:&MJCachedPropertiesKey]; |
| 181 | + [self dictForKey:&MJCachedPropertiesKey][NSStringFromClass(self)] = cachedProperties; |
158 | 182 | } |
159 | 183 |
|
160 | 184 | return cachedProperties; |
@@ -193,22 +217,22 @@ + (void)mj_setupObjectClassInArray:(MJObjectClassInArray)objectClassInArray |
193 | 217 | { |
194 | 218 | [self mj_setupBlockReturnValue:objectClassInArray key:&MJObjectClassInArrayKey]; |
195 | 219 |
|
196 | | - [[MJDictionaryCache dictWithDictId:&MJCachedPropertiesKey] removeAllObjects]; |
| 220 | + [[self dictForKey:&MJCachedPropertiesKey] removeAllObjects]; |
197 | 221 | } |
198 | 222 |
|
199 | 223 | #pragma mark - key配置 |
200 | 224 | + (void)mj_setupReplacedKeyFromPropertyName:(MJReplacedKeyFromPropertyName)replacedKeyFromPropertyName |
201 | 225 | { |
202 | 226 | [self mj_setupBlockReturnValue:replacedKeyFromPropertyName key:&MJReplacedKeyFromPropertyNameKey]; |
203 | 227 |
|
204 | | - [[MJDictionaryCache dictWithDictId:&MJCachedPropertiesKey] removeAllObjects]; |
| 228 | + [[self dictForKey:&MJCachedPropertiesKey] removeAllObjects]; |
205 | 229 | } |
206 | 230 |
|
207 | 231 | + (void)mj_setupReplacedKeyFromPropertyName121:(MJReplacedKeyFromPropertyName121)replacedKeyFromPropertyName121 |
208 | 232 | { |
209 | 233 | objc_setAssociatedObject(self, &MJReplacedKeyFromPropertyName121Key, replacedKeyFromPropertyName121, OBJC_ASSOCIATION_COPY_NONATOMIC); |
210 | 234 |
|
211 | | - [[MJDictionaryCache dictWithDictId:&MJCachedPropertiesKey] removeAllObjects]; |
| 235 | + [[self dictForKey:&MJCachedPropertiesKey] removeAllObjects]; |
212 | 236 | } |
213 | 237 | @end |
214 | 238 |
|
|
0 commit comments