//
// NSArray+beyond.h
// testRetainCount
//
// Created by jie on 16/5/10.
// Copyright © 2016年 jie. All rights reserved.
//
import <Foundation/Foundation.h>
@interface NSArray (beyond)
-(id)achieveSafeObjectAtIndex:(NSInteger)index;
@end
//
// NSArray+beyond.m
// testRetainCount
//
// Created by jie on 16/5/10.
// Copyright © 2016年 jie. All rights reserved.
//
import "NSArray+beyond.h"
@implementation NSArray (beyond)
-(id)achieveSafeObjectAtIndex:(NSInteger)index{
if (index >= 0 && index < self.count) {
id obj = [self objectAtIndex:index];
return obj;
}else{
NSAssert(index < self.count, @"数组越界");
}
return nil;
}
@end
NSArray *array = @[@"1",@"2",@"3",@"4"];
id obj = [array achieveSafeObjectAtIndex:1];
NSLog(@"%@",obj);