icon ArrayとDictionary (2015/08/05)

Array

var 変数:Array<型> = []; //[]で初期化
var 変数[型] = []; //Arrayを省略

Dictionary

var 変数:Dictionary<キー型, 値型> = [:]; //[:]で初期化
//変数["キー"]でアクセス可能

サンプル

var areas:[Any] = [];
var area:Dictionary<String, String> = [:];

override func viewDidLoad() {
   super.viewDidLoad();
   let area1:Dictionary = ["code": "01", "name": "東京"];
   let area2:Dictionary = ["code": "02", "name": "大阪"];
   let area3:Dictionary = ["code": "03", "name": "名古屋"];
   areas.append(area1);
   areas.append(area2);
   areas.append(area3);
   areas.append(area4);

   let _area:Dictionary<String, String> = areas[3] as! Dictionary;
   println(_area);
   println(_area["name"]);
}