我有在Objective-C中创建和NSAlert的代码,但我现在想在Swift中创建它.
警报是确认用户想要删除文档.
我希望"删除"按钮然后运行删除功能和"取消"按钮只是为了解除警报.
我怎么能在Swift中写这个?
NSAlert *alert = [[[NSAlert alloc] init] autorelease];
[alert addButtonWithTitle:@"Delete"];
[alert addButtonWithTitle:@"Cancel"];
[alert setMessageText:@"Delete the document?"];
[alert setInformativeText:@"Are you sure you would like to delete the document?"];
[alert setAlertStyle:NSWarningAlertStyle];
[alert beginSheetModalForWindow:[self window] modalDelegate:self didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) contextInfo:nil];
Run Code Online (Sandbox Code Playgroud)