OC 언어 사전

    //  
//    NSDictionary *dic = [[NSDictionary alloc] init];
//    NSDictionary *dict = [NSDictionary dictionary];
    NSDictionary *diction = [[NSDictionary alloc] initWithObjectsAndKeys:@"1",@"2",@"3",@"4", nil] ;
    NSLog(@"%@", diction);
    //  
    NSDictionary *dic = @{@"1": @"2",@"3":@"4"};    //    
    NSLog(@"%@", dic);
    // key , value ,key ( )
    //  
    NSLog(@"%ld", diction.count);
    //  key value
    NSLog(@"%@", [diction objectForKey:@"2"]);
    // diction[ key]
    NSLog(@"%@", diction[@"2"]);
    //  key key value
    NSLog(@"%@", diction.allKeys);
    NSLog(@"%@", [diction allValues]);
    //  
    NSMutableDictionary *dictionary1 = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"1",@"2",@"3",@"4", nil];
    // for 
    for (NSInteger i = 0; i < dictionary1.count; i++) {
        NSLog(@"%@ = %@", dictionary1.allKeys[i],dictionary1.allValues[i]);
    }
    // forin key
    for (NSString *temp in dictionary1) {
        NSLog(@"%@ = %@", temp, dictionary1[temp]);
    }
    //  key 
    //  key 
    [dictionary1 setObject:@"7" forKey:@"8"];
    NSLog(@"%@", dictionary1);
    //  key 
    [dictionary1 setObject:@"199" forKey:@"8"];
    NSLog(@"%@", dictionary1);
    //  
    [dictionary1 setValue:nil forKey:@"8"];
    NSLog(@"%@", dictionary1);
    //  setValue setObject   value nil   key   Object 
    [dictionary1 setValue:@"199" forKey:@"8"];
    [dictionary1 removeObjectForKey:@"8"];
    NSLog(@"%@", dictionary1);
    //  
    NSArray *arr1 = @[@"1", @"2", @"3", @"4"];
    NSArray *arr2 = @[@"5", @"6", @"7", @"8"];
    NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:arr1,@"arr1",arr2,@"arr2", nil];
    //  
    for (NSString *str in dictionary) {
        //  key value,value , 
        NSArray *arr = dictionary[str];
        for (NSString *temp in arr) {
            NSLog(@"%@", temp);
        }
    }
    //  
    NSDictionary *dic1 = [NSDictionary dictionaryWithObjectsAndKeys:@" ",@"name",@"19",@"age", nil];
    NSDictionary *dic2 = [NSDictionary dictionaryWithObjectsAndKeys:@" ",@"name",@"20",@"age", nil];
    NSDictionary *dic3 = [NSDictionary dictionaryWithObjectsAndKeys:@" ",@"name",@"18",@"age", nil];
    NSDictionary *dic4 = [NSDictionary dictionaryWithObjectsAndKeys:@" ",@"name",@"21",@"age", nil];
    NSArray *array = @[dic1,dic2,dic3,dic4];
    //  
    for (NSDictionary *dic in array) {
        for (NSString *key in dic) {
            NSLog(@"%@", dic[key]);
        }
    }
    //  
    //  
    NSArray *array1 = @[dic1,dic2];
    NSArray *array2 = @[dic3,dic4];
    NSDictionary *bigDic = [NSDictionary dictionaryWithObjectsAndKeys:array1, @"array1",array2,@"array2", nil];
    //  
    for (NSString *str in bigDic) {
        NSArray *arr = bigDic[str];
        for (NSDictionary *dic in arr) {
            for (NSString *key in dic) {
                NSLog(@"%@", dic[key]);
            }
        }
    }
    //  
    NSArray *bigArr = @[array1, array2];
    for (NSArray *arr in bigArr) {
        for (NSDictionary *dic in arr) {
            for (NSString *key in dic) {
                NSLog(@"%@", dic[key]);
            }
        }
    }
    //  , forin key NSString , key value , forin
    //  
    NSMutableDictionary *book1 = [NSMutableDictionary dictionaryWithObjectsAndKeys:@" ",@"name",@"100",@"price",nil];
    NSMutableDictionary *book2 = [NSMutableDictionary dictionaryWithObjectsAndKeys:@" ",@"name",@"200",@"price",nil];
    NSMutableDictionary *book3 = [NSMutableDictionary dictionaryWithObjectsAndKeys:@" ",@"name",@"300",@"price",nil];
    NSMutableDictionary *book4 = [NSMutableDictionary dictionaryWithObjectsAndKeys:@" ",@"name",@"400",@"price",nil];
    NSMutableDictionary *book5 = [NSMutableDictionary dictionaryWithObjectsAndKeys:@" ",@"name",@"500",@"price",nil];
    NSMutableArray *arr = [NSMutableArray arrayWithObjects:book1,book2,book3,book4,nil];
    //  
    [arr addObject:book5];
    //  
    [arr removeObject:book4];
    //  
    for (NSDictionary *dic in arr) {
        if ([dic[@"name"] isEqualToString:@" "]) {
            [dic setValue:@"600" forKey:@"price"];
        }
    }
    for (NSMutableDictionary *dic in arr) {
        for (NSString *temp in dic) {
            NSLog(@"%@ = %@", temp, dic[temp]);
        }
    }
    NSLog(@"**************");
    //  
    for (NSMutableDictionary *dic in arr) {
        for (NSInteger i = 0; i < dic.count; i++) {
            NSLog(@"%@ = %@", dic.allKeys[i], dic.allValues[i]);
        }
    }

좋은 웹페이지 즐겨찾기