I upgraded to Xcode 10.2 yesterday and started using Swift 5 and notice this error when bringing up my UIAlertController
photo prompt. I don't remember seeing it in Xcode 10.1
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x600001321e00 UIView:0x7fe1246070a0.width == - 16 (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
I read this issue How to trap on UIViewAlertForUnsatisfiableConstraints?
and was able to pin point the error to my UIAlertController
(highlighted in red)
Here's my code:
@objc private func promptPhoto() {
let prompt = UIAlertController(title: "Choose a Photo",
message: "",
preferredStyle: .actionSheet)
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
let camerAction = UIAlertAction(title: "Camera", style: .default) { _ in
guard self.isCameraAccessible() else {
self.showAlert(title: "Oops", message: "Camera is not available")
return
}
imagePicker.sourceType = .camera
imagePicker.allowsEditing = true
self.present(imagePicker, animated: true)
}
let libraryAction = UIAlertAction(title: "Photo Library", style: .default) { _ in
imagePicker.sourceType = .photoLibrary
imagePicker.allowsEditing = true
self.present(imagePicker, animated: true)
}
let cancelAction = UIAlertAction(title: "Cancel",
style: .cancel,
handler: nil)
prompt.addAction(camerAction)
prompt.addAction(libraryAction)
prompt.addAction(cancelAction)
present(prompt, animated: true) {
// Prevent closing the prompt by touch up outside the prompt.
prompt.view.superview?.subviews[0].isUserInteractionEnabled = false
}
}
I've tried playing around setting the width of my UIAlertController
by using this code inside my promptPhoto()
method to no avail.
let width: NSLayoutConstraint = NSLayoutConstraint(item: prompt.view!,
attribute: NSLayoutConstraint.Attribute.width,
relatedBy: NSLayoutConstraint.Relation.equal,
toItem: nil,
attribute: NSLayoutConstraint.Attribute.notAnAttribute,
multiplier: 1,
constant: self.view.frame.width)
prompt.view.addConstraint(width)
Is there a way to control the UIAlertController
width so that I could get rid of my error message?
Thank you in advance.
Build Setting -> Swift Compiler - Language
usingSwift 5
orSwift 4.2
? – Silvery