#import <Foundation/Foundation.h>
@interface NSMutableArray (FilterElement)
/**
* 过滤掉相同的元素
*
* @return 返回一个数组
*/
- (NSMutableArray*)filterTheSameElement;
@end
#import "NSMutableArray+FilterElement.h"
@implementation NSMutableArray (FilterElement)
/**
* 过滤掉相同的元素
*
* @return 返回一个数组
*/
- (NSMutableArray*)filterTheSameElement
{
NSMutableSet *set = [NSMutableSet set];
for (NSObject *obj in self) {
[set addObject:obj];
}
[self removeAllObjects];
for (NSObject *obj in set) {
[self addObject:obj];
}
return self;
}
@end