#import "NSMutableArray+FKAdd.h"
@implementation NSMutableArray (FKAdd)
- (void)fk_addObject:(id)anObject {
if (!anObject) {
NSAssert(anObject, @"warning: 请不要添加空数据!");
return;
}
if (self == anObject) {
NSAssert(anObject != self, @"warning: 请不要添加自身!");
return;
}
[self addObject:anObject];
}
- (void)fk_insertObject:(id)anObject atIndex:(NSUInteger)index {
if (index < 0) {
NSAssert(index >= 0, @"warning: 插入的下标为负!");
return;
}
if (index > self.count) {
NSAssert(index <= self.count, @"warning: 插入的下标越界!");
return;
}
if (!anObject) {
NSAssert(anObject, @"warning: 请不要添加空数据!");
return;
}
if (self == anObject) {
NSAssert(anObject != self, @"warning: 请不要插入自身!");
return;
}
[self insertObject:anObject atIndex:index];
}
- (void)fk_removeObjectAtIndex:(NSUInteger)index {
if (index < 0) {
NSAssert(index >= 0, @"warning: 移除的下标为负!");
return;
}
if (index >= self.count) {
NSAssert(index < self.count, @"warning: 移除的下标越界!");
return;
}
[self removeObjectAtIndex:index];
}
- (void)fk_replaceObjectAtIndex:(NSUInteger)index withObject:(id)anObject {
if (index < 0) {
NSAssert(index >= 0, @"warning: 替换的下标为负!");
return;
}
if (index >= self.count) {
NSAssert(index < self.count, @"warning: 替换的下标越界!");
return;
}
if (!anObject) {
NSAssert(anObject, @"warning: 请不要用空数据替换!");
return;
}
if (self == anObject) {
NSAssert(self != anObject, @"warning: 请不要用自身进行替换!");
return;
}
[self replaceObjectAtIndex:index withObject:anObject];
}
- (NSMutableArray*(^)(id))fk_addObject {
return ^NSMutableArray*(id anObject) {
if (!anObject) {
NSAssert(anObject, @"warning: 请不要添加空数据!");
return self;
}
if (self == anObject) {
NSAssert(self != anObject, @"warning: 请不要添加自身!");
return self;
}
[self addObject:anObject];
return self;
};
}
- (NSMutableArray*(^)(NSUInteger))fk_removeObjectAtIndex {
return ^NSMutableArray*(NSUInteger index) {
if (index < 0) {
NSAssert(index >= 0, @"warning: 移除的下标为负!");
return self;
}
if (index >= self.count) {
NSAssert(index < self.count, @"warning: 移除的下标越界!");
return self;
}
[self removeObjectAtIndex:index];
return self;
};
}
@end