这就是我现在所拥有的:
enum TestKeys: String {
case login = "login"
case username = "username"
}
var testData: Dictionary<String,AnyObject> = // a dictionary of known key/values
// I want the return value from this function to be typed
func getTestObject(key: TestKeys) -> AnyObject! {
if let obj: AnyObject = testData[key.rawValue] {
return obj
} else {
assertionFailure("We cannot find \(key.rawValue) in our testData")
return nil
}
}
我事先知道字典中的键和特定值类型。我希望能够做的是将一个类型与每个键相关联,这样当我访问字典的内容时我可以有类型的返回值。