Skip to content

Commit

Permalink
一些小问题
Browse files Browse the repository at this point in the history
1.某些属性的懒加载转为init初始化
2.过期方法处理
3.用更简单的方法过滤NSObject自动生成的属性
  • Loading branch information
520dev committed Jul 22, 2016
1 parent e908cea commit 71f94be
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 21 deletions.
2 changes: 1 addition & 1 deletion MJExtension.podspec
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "MJExtension"
s.version = "3.0.12"
s.version = "3.0.13"
s.ios.deployment_target = '6.0'
s.osx.deployment_target = '10.8'
s.summary = "A fast and convenient conversion between JSON and model"
Expand Down
15 changes: 4 additions & 11 deletions MJExtension/MJProperty.m
Expand Up @@ -18,21 +18,14 @@ @interface MJProperty()

@implementation MJProperty

#pragma mark - 懒加载
- (NSMutableDictionary *)propertyKeysDict
#pragma mark - 初始化
- (instancetype)init
{
if (!_propertyKeysDict) {
if (self = [super init]) {
_propertyKeysDict = [NSMutableDictionary dictionary];
}
return _propertyKeysDict;
}

- (NSMutableDictionary *)objectClassInArrayDict
{
if (!_objectClassInArrayDict) {
_objectClassInArrayDict = [NSMutableDictionary dictionary];
}
return _objectClassInArrayDict;
return self;
}

#pragma mark - 缓存
Expand Down
9 changes: 2 additions & 7 deletions MJExtension/NSObject+MJProperty.m
Expand Up @@ -163,13 +163,8 @@ + (NSMutableArray *)properties
// 2.遍历每一个成员变量
for (unsigned int i = 0; i<outCount; i++) {
MJProperty *property = [MJProperty cachedPropertyWithProperty:properties[i]];
// 过滤掉系统自动添加的元素
if ([property.name isEqualToString:@"hash"]
|| [property.name isEqualToString:@"superclass"]
|| [property.name isEqualToString:@"description"]
|| [property.name isEqualToString:@"debugDescription"]) {
continue;
}
// 过滤掉Foundation框架类里面的属性
if ([MJFoundation isClassFromFoundation:property.srcClass]) continue;
property.srcClass = c;
[property setOriginKey:[self propertyKey:property.name] forClass:self];
[property setObjectClassInArray:[self propertyObjectClassInArray:property.name] forClass:self];
Expand Down
4 changes: 3 additions & 1 deletion MJExtension/NSString+MJExtension.m
Expand Up @@ -72,8 +72,10 @@ - (BOOL)mj_isPureInt
- (NSURL *)mj_url
{
// [self stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet characterSetWithCharactersInString:@"!$&'()*+,-./:;=?@_~%#[]"]];

#pragma clang diagnostic push
#pragma clang diagnostic ignored"-Wdeprecated-declarations"
return [NSURL URLWithString:(NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)self, (CFStringRef)@"!$&'()*+,-./:;=?@_~%#[]", NULL,kCFStringEncodingUTF8))];
#pragma clang diagnostic pop
}
@end

Expand Down
2 changes: 1 addition & 1 deletion MJExtensionExample/main.m
Expand Up @@ -352,7 +352,7 @@ void coreData()
// 利用CoreData保存模型
[context save:nil];

MJExtensionLog(@"name=%@, icon=%@, age=%zd, height=%f, money=%@, sex=%d, gay=%d", user.name, user.icon, user.age, user.height, user.money, user.sex, user.gay);
MJExtensionLog(@"name=%@, icon=%@, age=%zd, height=%@, money=%@, sex=%d, gay=%d", user.name, user.icon, user.age, user.height, user.money, user.sex, user.gay);
}

/**
Expand Down

0 comments on commit 71f94be

Please sign in to comment.