I've taken over some Swift 2 code and trying to bring it up to Swift 3 (Xcode 8.3), but I'm stuck on one line.
The code is checking to see if a host is connected:
func isHostConnected(hostAddress : String) -> Bool {
let request = NSMutableURLRequest(url: NSURL(string: hostAddress.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)!)! as URL)
request.timeoutInterval = 3
request.httpMethod = "HEAD"
let session = URLSession(configuration: URLSessionConfiguration.default)
var responseCode = -1
let group = DispatchGroup.init()
group.enter()
session.dataTask(with: request as URLRequest, completionHandler: {(_, response, _) in
if let httpResponse = response as? HTTPURLResponse {
responseCode = httpResponse.statusCode
}
group.leave()
}).resume()
group.wait(timeout: dispatch_time_t(DispatchTime.distantFuture)) //ERROR LINE
return (responseCode == 401)
}
I am getting an error on the line:
group.wait(timeout: dispatch_time_t(DispatchTime.distantFuture))
which reads:
Cannot invoke initializer for type 'dispatch_time_t' with an argument list of type '(DispatchTime)'
So it seems to be looking for an object of type DispatchTime
as the parameter but I can't seem to find an answer on Google to match .distantFuture
Also, if I try:
group.wait(timeout: dispatch_time_t(.distantFuture))
I get an error saying:
Type of expression is ambiguous without more context
Thanks.