LoginSignup
1
1

More than 5 years have passed since last update.

Swiftメモ AnyになったDictionaryからワンライナーで値を取り出す

Last updated at Posted at 2017-06-06
func hoge() -> Any {
    return ["name": "aaa", "age": 10]
}

var d = hoge()
print(d)

// ワンライナーで値取得
(d as! [String: Any])["name"]   //=> "aaa"

// Anyなやつがホントは何か知る方法のイディオム(get class name)
String(describing: type(of: d)) //=> "Dictionary<String, Any>"
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1