OC基础 Foundation基础 NSDictionary

Posted zhangqing979797

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了OC基础 Foundation基础 NSDictionary相关的知识,希望对你有一定的参考价值。

main

 

 

#import <Foundation/Foundation.h>

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":@"786577908@qq.com"};
        NSDictionary* contact2 = @{@"name":@"Tom2",@"age":@35,@"tel":@"156455307923",@"email":@"786577908@qq.com"};
        
        NSMutableArray* contractbook=[[NSMutableArray alloc] init];
        [contractbook addObject:contact];
        [contractbook addObject:contact2];
        // 并不是按照顺序 也是hash table
        NSLog(@"%@",contractbook);
        
        
        
        
    }
    return 0;
}

 

以上是关于OC基础 Foundation基础 NSDictionary的主要内容,如果未能解决你的问题,请参考以下文章

OC系列foundation Kit基础-NSdictionary

OC系列foundation Kit基础-NSMutableString

OC系列foundation Kit基础-NSMutableArray

OC系列foundation Kit基础-NSString

OC系列foundation Kit基础-NSArray

OC系列foundation Kit基础-NSDate