123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- //
- // NSArray+Safe.m
- // RuiZhi
- //
- // Created by RD on 2020/6/16.
- // Copyright © 2020 RDIOT. All rights reserved.
- //
- #import "NSArray+Safe.h"
- @implementation NSArray (Safe)
- - (id)objectAtIndexSafe:(NSUInteger)index{
- if (index < self.count) {
- return [self objectAtIndex:index];
- }else{
- NSLog(@"%s 数组越界~~", __func__);
- return nil;
- }
- }
- @end
- @implementation NSMutableArray (Safe)
- - (id)objectAtIndexSafe:(NSUInteger)index{
- if (index < self.count) {
- return [self objectAtIndex:index];
- }else{
- NSLog(@"%@ 数组越界~~", [self class]);
- return nil;
- }
- }
- - (void)addObjectSafe:(id)anObject{
- if (anObject != nil && [anObject isKindOfClass:[NSNull class]] == NO) {
- [self addObject:anObject];
- } else {
- NSLog(@"%@ 数组插入nil~~", [NSThread callStackSymbols]);
-
- }
- }
- @end
|