iOS 防止数组越界的解决方法
代码:
#import <Foundation/Foundation.h> //防止数据越界 @interface NSArray (DXIndexCheckArray) - (id)objectAtIndexCheck:(NSUInteger)index; @end
#import "NSArray+DXIndexCheckArray.h" @implementation NSArray (DXIndexCheckArray) - (id)objectAtIndexCheck:(NSUInteger)index{ if (index > self.count) { return nil; } id value = [self objectAtIndex:index]; if (value == [NSNull null]) { return nil; } return value; } @end