數組 字典 複習

- (void)viewDidLoad

{

    [super viewDidLoad];

// Do any additional setup after loading the view.

    

    NSArray * arr = [NSArray arrayWithObjects:@"1",@"2",@"3",@"4",@"5", nil];

    

    NSDictionary * dic = [NSDictionary dictionaryWithObjectsAndKeys:arr,@"arr", nil]; //前面是對象 後面是名字

    

    NSLog(@"dic == %@",dic);

  2

    NSArray * arr = [NSArray arrayWithObjects:@"1",@"2",@"3",@"4",@"5", nil];

    NSDictionary * dic = [NSDictionary dictionaryWithObjectsAndKeys:arr,@"arr", nil];


    NSArray * dic2 = [NSArray arrayWithObjects:@"sad", nil];

     NSArray * name = [NSArray arrayWithObjects:@"arr", nil];



    NSDictionary * dic1 = [NSDictionary dictionaryWithObjects:dic2 forKeys:name];

    NSArray * a =[dic1 objectForKey:@"arr"];

    NSLog(@"a==%@",a);



    



    

    

    self.bigArray = [NSMutableArray array];

    NSLog(@"big array 1 == %@",_bigArray);

    

    NSMutableDictionary * dic = [NSMutableDictionary dictionary];

    NSLog(@"zidian 1 == %@",dic);

    

    [dic setObject:[UIColor redColor] forKey:@"redColor"];

    

    NSLog(@"1 == %@",dic);


    NSMutableArray * sArray = [NSMutableArray array];

    

    [sArray addObject:@"sad"];


    NSLog(@"%@",sArray);


    [dic setObject:sArray forKey:@"array"];

    

    NSLog(@"dic == %@",dic);


    [_bigArray addObject:dic];

    

    NSLog(@"1 == %@",_bigArray);


    [self insertIntoDic];

}



- (void) insertIntoDic

{

    

    for (NSMutableDictionary * dic in _bigArray) {

        NSMutableArray * array = [dic objectForKey:@"array"];

        [array addObject:@"111"];

    }

    NSLog(@"bigArray3 == %@",_bigArray);

    

    

    

}



    MainViewController * main = [[MainViewController alloc] init];  //根視圖控制器

    

    [_window setRootViewController:main];

    

    [main release];


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章