LoginSignup
11

More than 5 years have passed since last update.

[iOS8] Swiftで辞書型(Dictionary)を初期化する方法

Last updated at Posted at 2014-12-05

Swiftで辞書型配列を初期化する方法をサンプルコードを利用して説明していきます。

基本的に初期化には2パターンあります。

変数を新規生成

var dic  = [String: Int]()                    // 0key/value pairs

let dic2 = ["one": 1, "two": 2, "three": 3]   // ["one": 1, "two": 2, "three": 3]

dicが初期値無し、dic2は初期値有りです。

[ : ]で上書き

var dic3 = ["one": 1, "two": 2, "three": 3]  // ["one": 1, "two": 2, "three": 3]

dic3     = [:]  // 0 key/value pairs

 

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11