[swift-users] Optionals inside Dictionary where Value = Any

Daniel Eggert danieleggert at me.com
Wed Jan 6 04:47:41 CST 2016


I’m storing an Int? inside a [String:Any] but I can’t retrieve it again. Is this expected behaviour or a bug in Swift?

/Daniel

% swift
Welcome to Apple Swift version 2.2-dev (LLVM 3ebdbb2c7e, Clang f66c5bb67b, Swift 1f2908b4f7). Type :help for assistance.  3> let d: [String:Any] = ["foo": (nil as Int?)]
d: [String : Any] = 1 key/value pair {
  [0] = {
    key = "foo"
    value = {
      payload_data_0 = 0x0000000000000000
      payload_data_1 = 0x636c6f6f542f7201
      payload_data_2 = 0x77732f736e696168
      instance_type = 0x00000001004f6028
    }
  }
}
  4> let v = d["foo"]
v: Any? = Some {
  payload_data_0 = 0x0000000000000000
  payload_data_1 = 0x0000000000000001
  payload_data_2 = 0x0000000000000000
  instance_type = 0x00000001004f6028
}



More information about the swift-users mailing list