Created
April 20, 2016 14:16
-
-
Save phi161/2aa87e2df26f66f7146a7e6cff22c0cb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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