nal": [91, 66, 45, 28, 15, 6, 1],
/// "primes": [15, 13, 11, 7, 5, 3, 2],
/// "triangular": [28, 21, 15, 10, 6, 3, 1]]
// 遍历字典
let imagePaths = ["star": "/glyphs/star.png",
"portrait": "/images/content/portrait.jpg",
"spacer": "/images/shared/spacer.gif"]
for (key, value) in imagePaths {
print("The path to '\(key)' is '\(value)'.")
}
/// search a dictionary's contents for a particular value
// let glyphIndex = imagePaths.index {
// $0.value.hasPrefix("/glyphs")
// }
// print(imagePaths[glyphIndex!].value)// /glyphs/star.png
// print(imagePaths[glyphIndex!].key)// star
let glyphIndex = imagePaths.contains {
$0.value.hasPrefix("/glyphx")
}
print(glyphIndex)// ture
/// Bridging Between Dictionary and NSDictionary
// imagePaths as NSDictionary
print("keys:\((imagePaths as NSDictionary).allKeys) ,values:\((imagePaths as NSDictionary).allValues)")
}
|