「Swift」type(of:)でクラスの型を判定するサンプル
書式
type(of:オブジェクト名)
使用例
class Person {
let
}
// Personクラスを継承
class Student: Person {
let str = "study"
}
let cft = Student()
//クラスの型
print(type(of: cft))
//子クラス
print(cft is Student)
//スーパークラス
print(cft is Person)
実行結果
Student
true
true