Swift default AlertViewController breaking constraints

The following removes the warning without needing to disable animation. And assuming Apple eventually fixes the root cause of the warning, it shouldn’t break anything else.

extension UIAlertController {
    func pruneNegativeWidthConstraints() {
        for subView in self.view.subviews {
            for constraint in subView.constraints where constraint.debugDescription.contains("width == - 16") {
                subView.removeConstraint(constraint)
            }
        }
    }
}

This can then be used like this:

// After all addActions(...), just before calling present(...)
alertController.pruneNegativeWidthConstraints()

Leave a Comment