iOS Crash API

2020-03-28  本文已影响0人  孔朝阳

一、NSFoundation

1、NSArray (NSMutableArray)

1.1、objectAtIndex

example code

NSArray *array = @[@1, @2, @3];
NSLog(@"%@", [array objectAtIndex:3]);

crash info

*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 3 beyond bounds [0 .. 2]'

example code

NSArray *array = @[@1, @2, @3];
NSMutableArray *mutableArray = [NSMutableArray arrayWithArray:array];
NSLog(@"%@", [mutableArray objectAtIndex:3]);

crash info:

*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 3 beyond bounds [0 .. 2]'

1.2、array[index]

example code

NSArray *array = @[@1, @2, @3];
NSLog(@"%@", array[3]);

crash info:

*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndexedSubscript:]: index 3 beyond bounds [0 .. 2]'

example code

NSArray *array = @[@1, @2, @3];
NSMutableArray *mutableArray = [NSMutableArray arrayWithArray:array];
NSLog(@"%@", mutableArray[3]);

crash info:

*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndexedSubscript:]: index 3 beyond bounds [0 .. 2]'

2、NSMutableArray

2.1、addObject:

example code:

NSArray *array = @[@1, @2, @3];
NSMutableArray *mutableArray = [NSMutableArray arrayWithArray:array];
NSObject *object = nil;
[mutableArray addObject:object];
NSLog(@"%@", mutableArray[3]);

crash info:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'

3、NSMutableDictionary

3.1、setObject:forKey:

example code:

NSMutableDictionary *mutableDictionary = [NSMutableDictionary dictionary];
NSString *key = nil;
[mutableDictionary setObject:@"value" forKey:key];
NSLog(@"%@", mutableDictionary);

crash info:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSDictionaryM setObject:forKey:]: key cannot be nil'

example code:

NSMutableDictionary *mutableDictionary = [NSMutableDictionary dictionary];
NSString *key = @"key";
NSObject *value = nil;
[mutableDictionary setObject:value forKey:key];
NSLog(@"%@", mutableDictionary);

crash info:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSDictionaryM setObject:forKey:]: object cannot be nil (key: key)'
上一篇 下一篇

猜你喜欢

热点阅读