Skip to content

Instantly share code, notes, and snippets.

@phi161
Created April 20, 2016 14:16
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 phi161/2aa87e2df26f66f7146a7e6cff22c0cb to your computer and use it in GitHub Desktop.
Save phi161/2aa87e2df26f66f7146a7e6cff22c0cb to your computer and use it in GitHub Desktop.
// http://stackoverflow.com/questions/36744537/why-print-is-printing-my-string-as-an-optional
import UIKit
var input: [[String: AnyObject]] = [[:]]
input = [
["key": 101],
["key": 102],
["key": 103]
]
// This is what we want - the values from input to become String keys:
var desiredDictionary: [String: AnyObject] = [:]
desiredDictionary = [
"101": "whatever",
"102": "whatever",
"103": "whatever",
]
var output: [String: String] = [:]
for entry in input {
if let newKey = entry["key"] as? String {
output[newKey] = "whatever"
}
}
output
for entry in input {
let newKey: String = String(entry["key"]!)
output[newKey] = "whatever"
}
output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment