So this is a function from a class that lets you have a double tap and a single tap gesture. It's working fine in Swift 2.3, but after converting to Swift 3 it's throwing a few errors. I can't understand/figure out for the life of me. I commented where they occur.
// UIShortTapGestureRecognizer.swift
//
//
import Foundation
import UIKit
func delayHelper(_ time:TimeInterval, task:@escaping ()->()) -> DelayTask? {
func dispatch_later(_ block:@escaping ()->()) {
DispatchQueue.main.asyncAfter(
deadline: DispatchTime.now() + Double(Int64(time * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC),
execute: block)
}
var closure: ()->()? = task
var result: DelayTask?
let delayedClosure: DelayTask = {
cancel in
//Initializer for conditional binding must have Optional type, not '() -> ()?'
if let internalClosure = closure {
if (cancel == false) {
DispatchQueue.main.async(execute: internalClosure)
}
}
// here it says Nil cannot be assigned to type '() -> ()?'
closure = nil
result = nil
}
result = delayedClosure
dispatch_later {
if let delayedClosure = result {
delayedClosure(false)
}
}
return result;
}
func cancel(_ task:DelayTask?) {
task?(true)
}
}