Creating Dictionaries

Immutable dictionaries can be defined using the literal @{} syntax. But, like array literals, this was added relatively recently, so you should also be aware of the dictionaryWithObjectsAndKeys: and dictionaryWithObjects:forKeys: factory methods. All of these are presented below.

// Literal syntax
NSDictionary *inventory = @{
@"Mercedes-Benz SLK250" : [NSNumber numberWithInt:13],
@"Mercedes-Benz E350" : [NSNumber numberWithInt:22],
@"BMW M3 Coupe" : [NSNumber numberWithInt:19],
@"BMW X6" : [NSNumber numberWithInt:16],
};
// Values and keys as arguments
inventory = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:13], @"Mercedes-Benz SLK250",
[NSNumber numberWithInt:22], @"Mercedes-Benz E350",
[NSNumber numberWithInt:19], @"BMW M3 Coupe",
[NSNumber numberWithInt:16], @"BMW X6", nil];
// Values and keys as arrays
NSArray *models = @[@"Mercedes-Benz SLK250", @"Mercedes-Benz E350",
@"BMW M3 Coupe", @"BMW X6"];
NSArray *stock = @[[NSNumber numberWithInt:13],
[NSNumber numberWithInt:22],
[NSNumber numberWithInt:19],
[NSNumber numberWithInt:16]];
inventory = [NSDictionary dictionaryWithObjects:stock forKeys:models];
NSLog(@"%@", inventory);

时间: 2024-11-07 08:16:50

Creating Dictionaries的相关文章

在CentOS 6.3 安装postgresql9.5

一.安装准备 需要安装的包: yum install postgresql95-devel-9.5.5-1PGDG.rhel6.x86_64.rpm 文件可以从官网下载.http://yum.postgresql.org/repopackages.php 操作系统: CentOS release 6.3 (Final) 安装时如果提示yum源不对,注意调整rpm源如下: [[email protected] yum.repos.d]# cat pgdg-95-redhat.repo [pgdg9

From Disk partition to PostgreSQLinstallation

[[email protected] mnt]# fdisk /dev/sdb Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): n Partition type: p   primary (0 primar

Pacemaker+Corosync搭建PostgreSQL集群

https://my.oschina.net/aven92/blog/518928 · PostgreSQL中国社区: http://postgres.cn/index.php/home · PostgreSQL专业1群: 3336901(已满) · PostgreSQL专业2群: 100910388 · PostgreSQL专业3群: 150657323 一.环境 $ cat /etc/redhat-release  CentOS Linux release 7.0.1406 (Core) 

PostgreSQL中initdb做了什么

在使用数据库前,是启动数据库,启动数据库前是initdb(初始化数据库):一起来看一下initdb做了什么吧. 初始化数据库的操作为: ./initdb -D /usr/local/pgsql/data initdb把用户指定的选项转换成对应的参数,通过外部程序调用的方式执行postgres程序.postgres程序在这种方式下将进入bootstrap模式创建数据集簇,并读取后端接口postgres.bki文件来创建模板数据库. /*-------------------------------

Postgresql服务部署

PostgreSQL 是一种非常复杂的对象-关系型数据库管理系统(ORDBMS),也是目前功能最强大,特性最丰富和最复杂的自由软件数据库系统.os:centos6.5 x64 ip:192.168.85.130 hostname: vm2.lansgg.com pg 版本:postgresql-9.2.4.tar.bz2 一.yum安装二.源码安装 三.系统数据库 1.yum安装 [[email protected] ~]# wget  [[email protected] ~]# rpm -v

Some New Features in C# 6.0

Static Using Syntax In previous versions of C#, we would need to add the proper using statement, such as System, then we could write the following line of code: Console.WriteLine("Hello Abrar!"); With C# 6, you can now add the using statement an

OC中的Values——and——Collections

值和集合 在OC中可以使用C中的基本数据类型. 可以在类的实现里面对这些基本数据类型的属性进行C中的:++ – += -= *=等操作. 如下所示: //---------接口声明----------- @interface XYZPerson : NSObject @property int age; -(void)gettingOlder; @end //----------接口实现----------- @implementation XYZPerson -(void)gettingOld

源码安装Postgresql9.5

Postgresql简介: PostgreSQL是一个功能强大,开源对象关系型数据库系统.它拥有超过15年的持续开发和经验证的体系结构,赢得了良好的声誉:可靠性,数据完整性和正确性 官方号称: PostgreSQL: The world's most advanced open source database 官网下载地址:https://www.postgresql.org/download/ Postgresql部署: 环境: [[email protected] ~]# cat /etc/

如何在windows下手动初始化PostgreSQL数据库

环境:win7 64 sp1 PG:9.3.5 1.创建用户postgres,密码同样是postgres: net user postgres postgres /add 2.在数据库根目录下建立data目录: C:\Program Files\PostgreSQL\9.3>md data 3.去掉administrator对data目录的权限: C:\Program Files\PostgreSQL\9.3>cacls data /e /t /r administrator 处理的目录: C