This application is modifying the autolayout engine from a background thread, which can lead to engine corruption This application is modifying the autolayout engine from a background thread, which can lead to engine corruption multithreading multithreading

This application is modifying the autolayout engine from a background thread, which can lead to engine corruption


The dataTaskWithRequest call runs in the background and then calls your completion handler from the same thread. Anything that updates the UI should run on the main thread, so all of your current handler code should be within a dispatch_async back onto the main queue:

dispatch_async(dispatch_get_main_queue()) {  // Do stuff to UI}

Swift 3:

DispatchQueue.main.async() {  // Do stuff to UI}

Therefore, ideally all the code you currently have within if error == nil should be off in another function, say called handleRequest, so your current code becomes:

session.dataTaskWithRequest(request, completionHandler: {(data, response, error) in    if error == nil {        dispatch_async(dispatch_get_main_queue(), {            self.handleRequest(...)I        })    }


Swift 3

session.dataTaskWithRequest(request, completionHandler: {(data, response, error) inif error == nil {    DispatchQueue.main.async {        self.handleRequest(...)I    }}


Should try Symbolic Breakpoint to detect the issue:-enter image description here

Then put your UI Update code in main thread

DispatchQueue.main.async {}