LoginSignup
1
1

More than 3 years have passed since last update.

AnyとAnyObject

Last updated at Posted at 2019-05-22

Any

どんな型とも相当する。
関数型でもいい。

一貫性がない型のコレクション
let items: [Any] = [123, "ACB", 4.5, true]

AnyObject

クラスなら、どんな型にでも相当する。構造体とかはダメ。

キャストする

Any型はキャストして使う
if let firstItem = items.first as? Int {
    print(firstItem + 77)    // 200
}
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