After upgrading to Xcode 8 and converting all my code to Swift 3, I have troubles compiling swift resources. It takes a very long time, and my computer gets super laggy and
My case had to do with appending too many programmatically created constraints to a view controller's view. I had multiple arrays of constraints defined at the class level as follows:
lazy var labelConstraints: [NSLayoutConstraint] = [...]
I was using this notation for all UI elements in my view. By the time I was done building the view, I had roughly 10 arrays of 3-5 NSLayoutConstraints.
I was then appending a concatenated array to the view's constraint array like so:
self.view.addConstraints(labelConstraints + buttonConstraints + viewConstraints, ...)
This line turned out to be the problem. It must be something with lazy initialization and inline array concat. Whatever the cause, I have fixed this using flatMap as follows.
let constraints = [labelConstraints, buttonConstraints, viewConstraints].flatMap{ $0 }
self.view.addConstraints(constraints)