最終更新:2024-03-26 (火) 08:12:17 (23d)  

Swift/辞書
Top / Swift / 辞書

https://developer.apple.com/reference/swift/dictionary

var 変数:[タイプ:タイプ] = [タイプ:タイプ]()
var 変数:[タイプ:タイプ] = [キー1:値1,キー2:値2...]

メモ

  • 辞書.removeValueForKey?(キー)
  • 辞書.removeAll()
  • 辞書.keys
  • 辞書.values
  • 辞書.count

シンタックスシュガー

  • Dictionary<キーの型, 値の型> の型アノテーションは、シンタックシュガーを使って、[キーの型: 値の型] で書くことができます。
    let a: [String: Int] = ["key": 1, "key2": 2]

関連

  • LazyBidirectionalCollection?