Skip to content
This repository has been archived by the owner on Mar 29, 2018. It is now read-only.

Dictionary

pNre edited this page Jun 18, 2014 · 18 revisions

Contents

Instance Methods

Iteration

each

  • each (eachFunction each: (KeyType, ValueType) -> ())

Calls eachFunction for each (key, value) couple in self.

Examples

Without indexes
let dictionary = ["A": 1, "B": 2, "C": 3]
dictionary.each { key, value in println(key, value) }
/* Prints → */
// (A, 1)
// (B, 2)
// (C, 3)

Items accessing

has

  • has (key: KeyType) -> Bool

Returns true if key is in self, false otherwise.

Examples

Without indexes
let dictionary = ["A": 1, "B": 2, "C": 3]
dictionary.has("A")
// → true

pick, at

  • pick (keys: KeyType[]) -> Dictionary
  • pick (keys: KeyType...) -> Dictionary
  • at (keys: KeyType...) -> Dictionary

Return a copy of self, containing the couples (key, value) for the whitelisted keys.

Examples

Without indexes
let dictionary = ["A": 1, "B": 2, "C": 3, "D": 4]
dictionary.pick("A", "C")
// → ["A": 1, "C": 3]
Clone this wiki locally