一段测试NSArray和NSDictionary的代码

    NSLog(@"ENter did launch");
    NSArray *boyRoom = [[NSArray alloc] initWithObjects: @"strawhat", @"男生房间", @"入驻%d人",nil];
    NSArray *aquarium = [[NSArray alloc] initWithObjects: @"fish", @"养鱼馆", @"开放时间:%@",nil];
    NSArray *energeRoom = [[NSArray alloc] initWithObjects: @"energe", @"能源室", @"可乐数目:%d",nil];
    
    
    NSMutableDictionary *firstFloorDict = [[NSMutableDictionary alloc]init];
    [firstFloorDict setObject:boyRoom forKey:@"boyRoom"];
    [firstFloorDict setObject:aquarium forKey:@"aquarium"];
    [firstFloorDict setObject:energeRoom forKey:@"energeRoom"];
    
    [boyRoom release];
    [aquarium release];
    [energeRoom release];
    
    NSLog(@"Dict count:%d", [firstFloorDict count]);  
    NSEnumerator *enumeratorKey = [firstFloorDict keyEnumerator];  
    for (NSObject *object in enumeratorKey) {  
        NSLog(@"key:%@", object); 
        NSLog(@"value:\n"); 
        NSArray *objArray = [firstFloorDict objectForKey:object];
        for (NSObject *arrayObj in objArray){
            NSLog(@"val:%@", arrayObj);
        }
    }
    
    [firstFloorDict release];

你可能感兴趣的:(一段测试NSArray和NSDictionary的代码)