Xcode 8 (Swift 3) Command failed due to signal: Killed: 9

前端 未结 5 1762
一向
一向 2021-01-02 00:52

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

5条回答
  •  余生分开走
    2021-01-02 01:04

    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)
    

提交回复
热议问题