Skip to content

Instantly share code, notes, and snippets.

@KentarouKanno
Last active October 25, 2015 11:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KentarouKanno/10bb3fd96cf12e060b2e to your computer and use it in GitHub Desktop.
Save KentarouKanno/10bb3fd96cf12e060b2e to your computer and use it in GitHub Desktop.
let dict = ["key1":"value1","key2":"value2","key3":"value3"]
// 変数を宣言(初期値を設定)
var value1: String = "defaultValue"
// 値が取得できれば代入
if let tmpValue = dict["key"] {
value1 = tmpValue
}
// 変数を宣言(値が取得できれば代入、できなければ初期値を設定)
let value2 = dict["key"] ?? "defaultValue"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment