Swift クラスで条件分岐 isKind(of:) isMember(of:)

isKind(of:)

レシーバーが特定のクラスのインスタンスであるか、そのクラスから継承するクラスのインスタンスであるかを示すブール値を返します。

isMember(of:)

レシーバーが特定のクラスのインスタンスであるかどうかを示すブール値を返します。

上記関数を利用して、継承しているかどうかがわかる

f:id:happy_teeth_ago:20210422120547p:plain

条件分岐

   private func setUpPlaceholder(){

//DiaryCreateControllerだけデフォルト値を入力する
        guard isMember(of: DiaryCreateController.self) else { return }
        title_1.text = "first good things in today!"
        title_2.text = "second good things in today!"
        title_3.text = "third good things in today!"
        title_1.textColor = UIColor.lightGray
        title_2.textColor = UIColor.lightGray
        title_3.textColor = UIColor.lightGray
    }