I have encountered an unusual AppKit bug on macOS Tahoe. Specifically, certain NSAlert
's presented using [alert beginSheetForWindow:]
raises a conflicting constraint alert on the NSAlert
view itself. The code is very simple.
-(IBAction)presentAlert:(NSButton *)sender {
NSAlert *alert = NSAlert.alloc.init;
alert.alertStyle = NSAlertStyleInformational;
alert.messageText = @"Unable to locate volume.";
NSString *volumeName = @"My Volume";
alert.informativeText = [NSString stringWithFormat: @"Please attach or mount the volume named “%@”. If you can’t find this volume, or it was erased outside SuperDuper!, click Cancel.", volumeName];
alert.showsSuppressionButton = NO;
[alert addButtonWithTitle: @"Cancel"];
[alert.buttons[0] setTag: NSModalResponseCancel];
[alert layout]; // Commenting out this line of code will prevent the constraint exception but other alerts without layout() raise constraint violations
[alert beginSheetModalForWindow: self.window completionHandler: ^(NSModalResponse returnCode) {
NSLog(@"Done");
}];
}
When [alert beginSheetModalForWindow: self.window...]
is called, it raises the following conflicting constraint error.
Setting a symbolic breakpoint on LAYOUT_CONSTRAINTS_NOT_SATISFIABLE
shows that the constraint violation occurs within AppKit.
Furthermore, searching the view hierarchy for one of the violating constraints clearly shows that it is an auto layout constraint set by AppKit.
I ginned up two small Xcode projects, one in Objective-c and one in Swift and only the Objective-c variant raises the constraint violation.
NOTE: Removing [alert layout]
from the code above avoids the constraint violation in this instance but not all instances within the product hence there is a problem that manifests itself under certain circumstances but not all.
I have confirmed that bug occurs on Tahoe B1 and Tahoe B2 and filed FB18020308 accordingly but there haven't been any updates from Apple yet so I am posting here as well for ideas.