0

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?

Stafford Williams
  • 9,696
  • 8
  • 50
  • 101

4 Answers4

3

Wrap you r UI related login inside dispatch async and run it on main thread:

dispatch_async(dispatch_get_main_queue(),{

    self.view.hidden = true;

 })
Greg
  • 25,317
  • 6
  • 53
  • 62
3

Try this one, calling hidden on main thread.

dispatch_async(dispatch_get_main_queue(),{
   self.view.hidden = true;
})
turushan
  • 690
  • 7
  • 25
3

Rewrite your hide method as below. You need update UI on main thread only.

func hide() -> GCDWebServerDataResponse {
    dispatch_async(dispatch_get_main_queue(),{
        self.view.hidden = true
    })
    print("hide")
    return GCDWebServerDataResponse(statusCode: 200)
}
Hitendra Solanki
  • 4,871
  • 2
  • 22
  • 29
3

UI update code write in main thread only.

 dispatch_async(dispatch_get_main_queue(),{

        self.view.hidden = true;

     })
Aruna kumari
  • 329
  • 1
  • 11