美文网首页
创建模型属性代码的代码

创建模型属性代码的代码

作者: coderhlt | 来源:发表于2018-06-06 15:23 被阅读5次
    -(NSString *)PropertyNameCreatewithDict:(NSDictionary*)dict
    {
        NSMutableString *mutStr = [NSMutableString string];
        [dict enumerateKeysAndObjectsUsingBlock:^(id  _Nonnull propertyName, id  _Nonnull value, BOOL * _Nonnull stop) {
            NSLog(@"%@", [value class]);
            if ([value isKindOfClass:[NSNull class]])
            {
                return;
            }
            NSString *resultStr = @"";
            if ([value isKindOfClass:NSClassFromString(@"NSTaggedPointerString")]) {
                resultStr = [NSString stringWithFormat:@"@property (nonatomic, strong) NSString *%@;",propertyName];
            }else if ([NSStringFromClass([value class])containsString:@"Dictionary"]){
                 resultStr = [NSString stringWithFormat:@"@property (nonatomic, strong) NSDictionary *%@;",propertyName];
            }
            
            else if ([value isEqual:@""])
            {
                resultStr = [NSString stringWithFormat:@"@property (nonatomic, assign)NSString *%@;",propertyName];
            }
            else if ([value isKindOfClass:NSClassFromString(@"__NSCFBoolean")])
            {
                resultStr = [NSString stringWithFormat:@"@property (nonatomic, assign) BOOL %@;",propertyName];
            }
            else if ([NSStringFromClass([value class])containsString:@"Array"]){
                resultStr = [NSString stringWithFormat:@"@property (nonatomic, strong) NSArray *%@;",propertyName];
            }
            else if ([value isKindOfClass:NSClassFromString(@"__NSArrayI")])
            {
                resultStr = [NSString stringWithFormat:@"@property (nonatomic, strong) NSArray *%@;",propertyName];
            }
            else if ([value isKindOfClass:NSClassFromString(@"__NSDictionaryI ")])
            {
                resultStr = [NSString stringWithFormat:@"@property (nonatomic, strong) NSDictionary *%@;",propertyName];
            }
            else if ([value isKindOfClass:NSClassFromString(@"__NSCFNumber")])
            {
                resultStr = [NSString stringWithFormat:@"@property (nonatomic, assign) int %@;",propertyName];
            }
            else if ([value isKindOfClass:NSClassFromString(@"__NSCFDate")])
            {
                resultStr = [NSString stringWithFormat:@"@property (nonatomic, assign) NSDate *%@;",propertyName];
            }
    
            if (resultStr.length > 0) {
                [mutStr appendFormat:@"\n%@\n",resultStr];
            }
     
        }];
        return mutStr;
    }
    

    相关文章

      网友评论

          本文标题:创建模型属性代码的代码

          本文链接:https://www.haomeiwen.com/subject/fwbbsftx.html