iOS配列の境界を越えて、辞書の空の値の走潰防止処理
1802 ワード
https://github.com/MrLujh/SafeObject
//
NSArray *arr = @[@"1",@"2",@"2",@"2",@"2",@"2",@"2",@"2",@"2"];
NSMutableArray *tableArray = [[NSMutableArray alloc] initWithArray:arr];
NSLog(@"arr====%@ tableArray====%@",arr[100],tableArray[100]);
NSLog(@"arr====%@ tableArray====%@",[arr objectAtIndex:100],[tableArray objectAtIndex:100]);
//
NSDictionary *dict = @{@"name":@"",@"age":@"20"};
NSMutableDictionary *tableDict = [[NSMutableDictionary alloc] initWithDictionary:dict];
NSString *str= nil;
NSString *str1 = nil;
NSString *str2 = nil;
NSArray *arr1 = nil;
NSDictionary *dict1 = nil;
[tableDict setValue:str forKey:str1];
[tableDict setObject:str forKey:@"test"];
[tableDict setObject:arr1 forKey:@"arr"];
[tableDict setObject:dict1 forKey:str2];
id ss = [tableDict objectForKey:@"arr"];
if (ss == nil || [ss isKindOfClass:[NSNull class]]) {
NSLog(@"kong");
}
NSLog(@"dict---name====%@ tableDict---age====%@ tableDict---test====%@ tableDict---str1====%@ tableDict----arr=====%@ dict----dict=====%@",[dict objectForKey:@"name"],[tableDict objectForKey:@"age"],[tableDict objectForKey:@"test"],[tableDict objectForKey:str1],tableDict[@"arr"],tableDict[str2]);
NSLog(@"dict---name====%@ tableDict---age====%@",[dict objectForKey:@"name"],[tableDict objectForKey:@"age"]);
//
NSMutableString *tableString = [[NSMutableString alloc] initWithFormat:@" "];
NSLog(@"%@",[tableString substringFromIndex:100]);