Check if a subview is in a view using Swift

You can use the UIView method isDescendantOfView:

if mySubview.isDescendant(of: someParentView) {
    mySubview.removeFromSuperview()
} else {
    someParentView.addSubview(mySubview)
}

You may also need to surround everything with if mySubview != nil depending on your implementation.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)