数组为nil处理

2019-12-30  本文已影响0人  贝勒老爷
#import "NSMutableArray+Safe.h"
#import <objc/runtime.h>

@implementation NSMutableArray (Safe)

+ (void)load {
        Method orginalMethod = class_getInstanceMethod(NSClassFromString(@"__NSArrayM"), @selector(addObject:));
       Method newMethod = class_getInstanceMethod(NSClassFromString(@"__NSArrayM"), @selector(newAddobject:));
       method_exchangeImplementations(orginalMethod, newMethod);
}

- (void)newAddobject:(id)obj {
       if (obj != nil) {
          [self newAddobject:obj];
      }else{
        [self newAddobject:@""];
    }
}
上一篇 下一篇

猜你喜欢

热点阅读