This repository has been archived by the owner on Mar 29, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 317
Dictionary
pNre edited this page Jun 18, 2014
·
18 revisions
-
Instance methods
-
Operators
each (eachFunction each: (KeyType, ValueType) -> ())
Calls
eachFunction
for each(key, value)
couple inself
.
let dictionary = ["A": 1, "B": 2, "C": 3]
dictionary.each { key, value in println(key, value) }
/* Prints → */
// (A, 1)
// (B, 2)
// (C, 3)
has (key: KeyType) -> Bool
Returns
true
ifkey
is inself
,false
otherwise.
let dictionary = ["A": 1, "B": 2, "C": 3]
dictionary.has("A")
// → true
pick (keys: KeyType[]) -> Dictionary
pick (keys: KeyType...) -> Dictionary
at (keys: KeyType...) -> Dictionary
Return a copy of
self
, containing the couples(key, value)
for the whitelistedkeys
.
let dictionary = ["A": 1, "B": 2, "C": 3, "D": 4]
dictionary.pick("A", "C")
// → ["A": 1, "C": 3]
all (test: (KeyType, ValueType) -> (Bool)) -> Bool
Executes
test
on each(key, value)
inself
and returnstrue
iftest
returnstrue
for each couple,false
otherwise.
let dictionary = ["A": 1, "B": 2, "C": 3, "D": 4]
dictionary.all { key, value -> Bool in value > 0 }
// → true
dictionary.all { key, value -> Bool in key == "A" }
// → false
any (test: (KeyType, ValueType) -> (Bool)) -> Bool
Executes
test
on each(key, value)
inself
and returnstrue
iftest
returnstrue
for any couple,false
otherwise.
let dictionary = ["A": 1, "B": 2, "C": 3, "D": 4]
dictionary.any { key, value -> Bool in value < 0 }
// → false
dictionary.any { key, value -> Bool in key == "A" }
// → true