Supratik Majumdar Supratik Majumdar - 1 year ago 123
iOS Question

Remove View from SuperView with delay: Swift 3

I am trying to remove a view form the superView with a delay. I have the objective-c code for the same but an not able to implement it in Swift.

Code Snippet:

[self performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:6.5];

Answer Source

You can dispatch a closure to run after some delay and remove self from superview in the callback:

DispatchQueue.main.asyncAfter(deadline: .now() + 6.5) {

If you really want to use performSelector approach, here it is:

self.perform(#selector(self.removeFromSuperview), with: nil, afterDelay: 6.5)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download