Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Coder-256
Created June 5, 2016 15:51
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 Coder-256/5c13fa8d339da0eebb7fe093882bcdba to your computer and use it in GitHub Desktop.
Save Coder-256/5c13fa8d339da0eebb7fe093882bcdba to your computer and use it in GitHub Desktop.
import Cocoa
func returnsAString() -> AnyObject? {
return "I am a String."
}
func returnsAnInt() -> AnyObject? {
return Int(123)
}
func returnsABool() -> AnyObject? {
return true
}
func returnsNilBool() -> AnyObject? {
return nil as Bool?
}
var dict : [String : AnyObject] = [String : AnyObject]()
var newDict : [String : String ] = [String : String ]()
dict["string"] = returnsAString()
dict["int"] = returnsAnInt()
dict["bool"] = returnsABool()
dict["nil"] = returnsNilBool()
for (key, value) in dict {
switch value {
case is String:
newDict[key] = value as! String
case is Int:
newDict[key] = String(value as! Int)
case is Bool:
newDict[key] = (value as! Bool ? "1" : "0")
default:
newDict[key] = String(value)
}
}
print("Dict: \(dict)")
print("newDict: \(newDict)")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment