汉字

作者: 张家杰仔 | 来源:发表于2017-04-06 10:41 被阅读11次
    + (NSMutableArray *)valuesForamtToStringWithArray:(NSArray *)array {
        NSMutableArray * newArray = [NSMutableArray array];
        for (id obj in array) {
            id newObj;
            if ([obj isKindOfClass:[NSNumber class]]) {
                newObj = [NSString stringWithFormat:@"%@",obj];
            }else if ([obj isKindOfClass:[NSDictionary class]]) {
                newObj = [self valuesForamtToStringWithDict:obj];
            }else if ([obj isKindOfClass:[NSArray class]]){
                newObj = [self valuesForamtToStringWithArray:obj];
            }else if ([obj isKindOfClass:[NSNull class]]){
                newObj = @"";
            }else {
                newObj = obj;
            }
            [newArray addObject:newObj];
        }
        return newArray;
    }
    + (NSMutableDictionary *)valuesForamtToStringWithDict:(NSDictionary *)dict {
        __block NSMutableDictionary * newDict = [NSMutableDictionary dictionary];
        [dict enumerateKeysAndObjectsUsingBlock:^(id  _Nonnull key, id  _Nonnull obj, BOOL * _Nonnull stop) {
            NSString *newKey = [NSString stringWithFormat:@"%@",key];
            id newObj;
            if ([obj isKindOfClass:[NSNumber class]]) {
                newObj = [NSString stringWithFormat:@"%@",obj];
            }else if ([obj isKindOfClass:[NSDictionary class]]) {
                newObj = [self valuesForamtToStringWithDict:obj];
            }else if ([obj isKindOfClass:[NSArray class]]){
                newObj = [self valuesForamtToStringWithArray:obj];
            }else if ([obj isKindOfClass:[NSNull class]]){
                newObj = @"";
            }else {
                newObj = obj;
            }
            newDict[newKey] = newObj;
        }];
        return newDict;
    }
    

    相关文章

      网友评论

          本文标题:汉字

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