I am trying to call a function with optional CompletionHandler
parameter from a timer. Below is my code snippet:
typealias CompletionHandler = () -> Void
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: #selector(ViewController.check(_:)), userInfo: nil, repeats: false)
}
func check(completion: CompletionHandler?) {
print("userinfo1")
}
}
When the timer is triggered after 1.0
second, my app is dead with EXC_BAD_ACCESS
and the pointer points to class AppDelegate: UIResponder, UIApplicationDelegate
in AppDelegate
.
Can you show me how I can call check
function with such parameter? (If completion
is just an Int, the timer did work!)
Thanks