I defined a function with a generic closure parameter, like this:
final class Utils {
static func asyncTask<T>(task: () -> T, main: (res: T) -> Void) {
dispatch_async(dispatch_get_global_queue(0, 0)) {
let result = task()
dispatch_async(dispatch_get_main_queue()) {
main(res: result)
}
}
}
}
Then, I call it:
Utils.asyncTask({ () -> Int? in
let rows = self.cursor.db.query(true)
if !rows.isEmpty {
return (rows[0] as? BookMark)?.rowId
}
return nil
}) { rowId in
}
But I got a compile-time error:
Cannot convert value of type '() -> Int?' to expected argument type '() -> _'
Why?
Swift does supports generic closure as a function parameters, doesn't it?
Anybody can help me?
Thx.