码迷,mamicode.com
首页 > 其他好文 > 详细

OC基础 Foundation基础 NSDictionary

时间:2020-07-10 00:02:17      阅读:72      评论:0      收藏:0      [点我收藏+]

标签:style   with   js for   init   object   har   nil   add   信息   

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

标签:style   with   js for   init   object   har   nil   add   信息   

原文地址:https://www.cnblogs.com/zhangqing979797/p/13276953.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!