From 3e8437ae559487362fae3525beb79c534c213a51 Mon Sep 17 00:00:00 2001 From: 单军华 Date: Thu, 12 Jul 2018 13:44:34 +0800 Subject: [PATCH] bug修复和功能优化 --- screendisplay/Pods/MJExtension/MJExtension/MJProperty.m | 191 +++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 191 insertions(+), 0 deletions(-) diff --git a/screendisplay/Pods/MJExtension/MJExtension/MJProperty.m b/screendisplay/Pods/MJExtension/MJExtension/MJProperty.m new file mode 100644 index 0000000..ff57c6c --- /dev/null +++ b/screendisplay/Pods/MJExtension/MJExtension/MJProperty.m @@ -0,0 +1,191 @@ +// +// MJProperty.m +// MJExtensionExample +// +// Created by MJ Lee on 15/4/17. +// Copyright (c) 2015��� ���������. All rights reserved. +// + +#import "MJProperty.h" +#import "MJFoundation.h" +#import "MJExtensionConst.h" +#import <objc/message.h> + +@interface MJProperty() +@property (strong, nonatomic) NSMutableDictionary *propertyKeysDict; +@property (strong, nonatomic) NSMutableDictionary *objectClassInArrayDict; +@end + +@implementation MJProperty + +#pragma mark - ��������� +- (instancetype)init +{ + if (self = [super init]) { + _propertyKeysDict = [NSMutableDictionary dictionary]; + _objectClassInArrayDict = [NSMutableDictionary dictionary]; + } + return self; +} + +#pragma mark - ������ ++ (instancetype)cachedPropertyWithProperty:(objc_property_t)property +{ + MJExtensionSemaphoreCreate + MJExtensionSemaphoreWait + MJProperty *propertyObj = objc_getAssociatedObject(self, property); + if (propertyObj == nil) { + propertyObj = [[self alloc] init]; + propertyObj.property = property; + objc_setAssociatedObject(self, property, propertyObj, OBJC_ASSOCIATION_RETAIN_NONATOMIC); + } + MJExtensionSemaphoreSignal + return propertyObj; +} + +#pragma mark - ������������ +- (void)setProperty:(objc_property_t)property +{ + _property = property; + + MJExtensionAssertParamNotNil(property); + + // 1.��������� + _name = @(property_getName(property)); + + // 2.������������ + NSString *attrs = @(property_getAttributes(property)); + NSUInteger dotLoc = [attrs rangeOfString:@","].location; + NSString *code = nil; + NSUInteger loc = 1; + if (dotLoc == NSNotFound) { // ������, + code = [attrs substringFromIndex:loc]; + } else { + code = [attrs substringWithRange:NSMakeRange(loc, dotLoc - loc)]; + } + _type = [MJPropertyType cachedTypeWithCode:code]; +} + +/** + * ������������������������ + */ +- (id)valueForObject:(id)object +{ + if (self.type.KVCDisabled) return [NSNull null]; + return [object valueForKey:self.name]; +} + +/** + * ������������������������ + */ +- (void)setValue:(id)value forObject:(id)object +{ + if (self.type.KVCDisabled || value == nil) return; + [object setValue:value forKey:self.name]; +} + +/** + * ���������������key���������������keys + */ +- (NSArray *)propertyKeysWithStringKey:(NSString *)stringKey +{ + if (stringKey.length == 0) return nil; + + NSMutableArray *propertyKeys = [NSMutableArray array]; + // ��������������������� + NSArray *oldKeys = [stringKey componentsSeparatedByString:@"."]; + + for (NSString *oldKey in oldKeys) { + NSUInteger start = [oldKey rangeOfString:@"["].location; + if (start != NSNotFound) { // ������������key + NSString *prefixKey = [oldKey substringToIndex:start]; + NSString *indexKey = prefixKey; + if (prefixKey.length) { + MJPropertyKey *propertyKey = [[MJPropertyKey alloc] init]; + propertyKey.name = prefixKey; + [propertyKeys addObject:propertyKey]; + + indexKey = [oldKey stringByReplacingOccurrencesOfString:prefixKey withString:@""]; + } + + /** ������������ **/ + // ������ + NSArray *cmps = [[indexKey stringByReplacingOccurrencesOfString:@"[" withString:@""] componentsSeparatedByString:@"]"]; + for (NSInteger i = 0; i<cmps.count - 1; i++) { + MJPropertyKey *subPropertyKey = [[MJPropertyKey alloc] init]; + subPropertyKey.type = MJPropertyKeyTypeArray; + subPropertyKey.name = cmps[i]; + [propertyKeys addObject:subPropertyKey]; + } + } else { // ���������������key + MJPropertyKey *propertyKey = [[MJPropertyKey alloc] init]; + propertyKey.name = oldKey; + [propertyKeys addObject:propertyKey]; + } + } + + return propertyKeys; +} + +/** ���������������������key */ +- (void)setOriginKey:(id)originKey forClass:(Class)c +{ + if ([originKey isKindOfClass:[NSString class]]) { // ������������������key + NSArray *propertyKeys = [self propertyKeysWithStringKey:originKey]; + if (propertyKeys.count) { + [self setPorpertyKeys:@[propertyKeys] forClass:c]; + } + } else if ([originKey isKindOfClass:[NSArray class]]) { + NSMutableArray *keyses = [NSMutableArray array]; + for (NSString *stringKey in originKey) { + NSArray *propertyKeys = [self propertyKeysWithStringKey:stringKey]; + if (propertyKeys.count) { + [keyses addObject:propertyKeys]; + } + } + if (keyses.count) { + [self setPorpertyKeys:keyses forClass:c]; + } + } +} + +/** ���������������������������key */ +- (void)setPorpertyKeys:(NSArray *)propertyKeys forClass:(Class)c +{ + if (propertyKeys.count == 0) return; + NSString *key = NSStringFromClass(c); + if (!key) return; + + MJExtensionSemaphoreCreate + MJExtensionSemaphoreWait + self.propertyKeysDict[key] = propertyKeys; + MJExtensionSemaphoreSignal +} + +- (NSArray *)propertyKeysForClass:(Class)c +{ + NSString *key = NSStringFromClass(c); + if (!key) return nil; + return self.propertyKeysDict[key]; +} + +/** ������������������������������ */ +- (void)setObjectClassInArray:(Class)objectClass forClass:(Class)c +{ + if (!objectClass) return; + NSString *key = NSStringFromClass(c); + if (!key) return; + + MJExtensionSemaphoreCreate + MJExtensionSemaphoreWait + self.objectClassInArrayDict[key] = objectClass; + MJExtensionSemaphoreSignal +} + +- (Class)objectClassInArrayForClass:(Class)c +{ + NSString *key = NSStringFromClass(c); + if (!key) return nil; + return self.objectClassInArrayDict[key]; +} +@end -- Gitblit v1.8.0