iOS 배열이 경계를 벗어나 사전 빈 값의 충돌 방지 처리

1823 단어 iOS
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]);

좋은 웹페이지 즐겨찾기