标签:pre blog ffffff code 5.0 mutable nbsp ceo index
- (NSArray *)clearAllNullObject{ NSMutableArray *array = [self mutableCopy]; for (int i = 0;i < array.count;i++) { id obj = array[i]; if ([obj isKindOfClass:[NSDictionary class]]){ NSMutableDictionary *dict = [obj mutableCopy]; for (int j = 0; j<dict.allKeys.count; j++) { id tObj = dict[dict.allKeys[j]]; if ([tObj isKindOfClass:[NSNull class]]){ [dict removeObjectForKey:dict.allKeys[j]]; j--; } if ([tObj isKindOfClass:[NSArray class]]){ NSArray *to = [tObj clearAllNullObject]; [dict setObject:to forKey:dict.allKeys[j]]; } } [array replaceObjectAtIndex:i withObject:dict]; } if ([obj isKindOfClass:[NSArray class]]){ [array replaceObjectAtIndex:i withObject:[obj clearAllNullObject]]; } } return array; }
使用方法:
创建NSArray的category
NSArray *obj = [data clearAllNullObject];
标签:pre blog ffffff code 5.0 mutable nbsp ceo index
原文地址:http://www.cnblogs.com/n1ckyxu/p/6043998.html