Search code examples
iosswiftgcdwebserver

Updating UI as the result of a request handler


I have a setup like this;

startup() {
    ...
    self.gcdWebServer.addHandlerForMethod("GET", path: "/hide", 
        requestClass: GCDWebServerRequest.self, asyncProcessBlock: {request in self.hide()})
    ...
}

func hide() -> GCDWebServerDataResponse {
    self.view.hidden = true;
    print("hide")
    return GCDWebServerDataResponse(statusCode: 200)
}

When a request to /hide is made, the console shows the print() call immediately, but the view does not disappear for some arbitrary delay, somewhere between 10-30 seconds.

How can I have the request immediately result in the view being hidden?


Solution

  • Try this one, calling hidden on main thread.

    dispatch_async(dispatch_get_main_queue(),{
       self.view.hidden = true;
    })