-
-
Save Coder-256/5c13fa8d339da0eebb7fe093882bcdba to your computer and use it in GitHub Desktop.
This file contains 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
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