OC基础 Foundation基础 NSDictionary

main

 

 

#import 

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        NSDictionary* dic =[NSDictionary dictionaryWithObject:@1 forKey:@"1"];
        NSDictionary* dic2=@{@"1":@1,@"2":@2};
        NSDictionary* dic3=[NSDictionary dictionaryWithObjectsAndKeys:@1,@"1",@2,@"2", nil];
        NSArray* objs=@[@1,@2];
        NSArray* keys=@[@"1",@"2"];
        NSDictionary* dic4 =[NSDictionary dictionaryWithObject:objs forKey:keys];
        
        //字典对象的使用
        id obj =[dic2 objectForKey:@"2"];
        NSLog(@"%@",obj);
        
        for(id key in dic3)
        {
            id obj =[dic2 objectForKey:key];
            NSLog(@"%@",obj);
        }
        
        // 用法 联系人的信息
        NSDictionary* contact = @{@"name":@"Tom",@"age":@25,@"tel":@"15645530792",@"email":@"[email protected]"};
        NSDictionary* contact2 = @{@"name":@"Tom2",@"age":@35,@"tel":@"156455307923",@"email":@"[email protected]"};
        
        NSMutableArray* contractbook=[[NSMutableArray alloc] init];
        [contractbook addObject:contact];
        [contractbook addObject:contact2];
        // 并不是按照顺序 也是hash table
        NSLog(@"%@",contractbook);
        
        
        
        
    }
    return 0;
}

 

你可能感兴趣的:(OC基础 Foundation基础 NSDictionary)