美文网首页
数组为nil处理

数组为nil处理

作者: 贝勒老爷 | 来源:发表于2019-12-30 11:54 被阅读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:@""];
    }
}

相关文章

网友评论

      本文标题:数组为nil处理

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