{"id":1533,"date":"2022-04-03T00:06:52","date_gmt":"2022-04-02T15:06:52","guid":{"rendered":"https:\/\/www.typea.info\/blog\/?p=1533"},"modified":"2022-04-03T12:00:20","modified_gmt":"2022-04-03T03:00:20","slug":"nsalert_macos","status":"publish","type":"post","link":"https:\/\/www.typea.info\/blog\/index.php\/2022\/04\/03\/nsalert_macos\/","title":{"rendered":"NSAlert \u3067\u30c0\u30a4\u30a2\u30ed\u30b0\u30dc\u30c3\u30af\u30b9\u3092\u4f5c\u6210(macos)"},"content":{"rendered":"<p><a href=\"https:\/\/www.typea.info\/blog\/index.php\/category\/cocoa\/\">Storyboard + Swift<\/a>\u3067macOS\u30a2\u30d7\u30ea\u306e\u5b66\u7fd2\u3002<\/p>\n<p>NSAlert\u3067\u30c0\u30a4\u30a2\u30ed\u30b0\u30dc\u30c3\u30af\u30b9\u3092\u8868\u793a\u3055\u305b\u308b\u3002<\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2022\/04\/nsalert.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" title=\"nsalert.png\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2022\/04\/nsalert.png\" alt=\"nsalert.png\" width=\"276\" height=\"211\" border=\"0\"><\/a><\/p>\n<h2>1.\u30b9\u30bf\u30a4\u30eb<\/h2>\n<ul>\n<li>\u30a2\u30e9\u30fc\u30c8\u3092\u30b7\u30fc\u30c8\u3068\u3057\u3066\u8868\u793a\u3059\u308b\u306b\u306f\u3001beginSheetModal(for:completionHandler:)<\/li>\n<li>\u30e2\u30fc\u30c0\u30eb\u306e\u30c0\u30a4\u30a2\u30ed\u30b0\u3068\u3057\u3066\u8868\u793a\u3059\u308b\u306b\u306f\u3001runModal()<\/li>\n<\/ul>\n<h2>2.\u8907\u6570\u30dc\u30bf\u30f3\u3092\u8868\u793a<\/h2>\n<p>\u3061\u3087\u3063\u3068\u7279\u6b8a\u3002\u307e\u305a\u3001\u4f4d\u7f6e(NSAlert<span style=\"text-decoration: underline;\"><strong>First<\/strong><\/span>ButtonReturn\u3001\u306a\u3069)\u3067\u8b58\u5225\u3055\u308c\u308b\u3088\u3046\u3060\u3002<\/p>\n<p>\u3053\u3061\u3089\u306f\u30b0\u30b0\u308b\u3068\u7d50\u69cb\u51fa\u3066\u304f\u308b\u306e\u3060\u304c\u3001\u30dc\u30bf\u30f3\u306e\u5f79\u5272\u3092\u4f4d\u7f6e\u3067\u8b58\u5225\u3059\u308b\u306e\u306f\u3057\u3063\u304f\u308a\u3053\u306a\u3044\u3001\u3001\u3001\u30b0\u30b0\u3063\u3066\u3082\u306a\u304b\u306a\u304b\u60c5\u5831\u304c\u306a\u304f\u3066\u308f\u304b\u308a\u306b\u304f\u304b\u3063\u305f\u304c\u3001tag\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3063\u3066\u5b9f\u73fe\u3067\u304d\u305f\u3002<\/p>\n<p><a href=\"https:\/\/developer.apple.com\/documentation\/appkit\/nsalert\/1524532-addbutton\">addButton(withTitle:) | Apple Developer Documentation<\/a><\/p>\n<ul>\n<li>\u30dc\u30bf\u30f3\u306f\u30a2\u30e9\u30fc\u30c8\u306e\u53f3\u5074\u304b\u3089\u5de6\u5074\u306b\u5411\u304b\u3063\u3066\u914d\u7f6e\u3055\u308c\u307e\u3059\uff08\u5de6\u304b\u3089\u53f3\u3078\u8aad\u3080\u8a00\u8a9e\u306e\u5834\u5408\uff09\u3002\u6700\u521d\u306e 3 \u3064\u306e\u30dc\u30bf\u30f3\u306f\u3001\u30e2\u30fc\u30c0\u30eb\u30c7\u30ea\u30b2\u30fc\u30c8\u306b\u3088\u3063\u3066\u8a55\u4fa1\u3055\u308c\u308b return-code \u30d1\u30e9\u30e1\u30fc\u30bf\u3067 NSAlertFirstButtonReturn\u3001NSAlertSecondButtonReturn\u3001NSAlertThirdButtonReturn \u3068\u3057\u3066\u4f4d\u7f6e\u7684\u306b\u8b58\u5225\u3055\u308c\u3066\u3044\u307e\u3059\u3002\u5f8c\u7d9a\u306e\u30dc\u30bf\u30f3\u306f\u3001NSAlertThirdButtonReturn +n \u3068\u3057\u3066\u8b58\u5225\u3055\u308c\u307e\u3059\uff08n \u306f\u6574\u6570\uff09<\/li>\n<li>\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u306f\u3001\u6700\u521d\u306e\u30dc\u30bf\u30f3\u306e\u30ad\u30fc\u306fReturn\u3001\u300c\u30ad\u30e3\u30f3\u30bb\u30eb\u300d\u3068\u3044\u3046\u30bf\u30a4\u30c8\u30eb\u306e\u30dc\u30bf\u30f3\u306fEscape\u3001\u300c\u4fdd\u5b58\u3057\u306a\u3044\u300d\u3068\u3044\u3046\u30bf\u30a4\u30c8\u30eb\u306e\u30dc\u30bf\u30f3\u306fCommand-D\u306b\u76f8\u5f53\u3057\u307e\u3059\uff08\u305f\u3060\u3057\u3001\u6700\u521d\u306e\u30dc\u30bf\u30f3\u3067\u306a\u3044\u5834\u5408\u306e\u307f\uff09\u3002\u307e\u305f\u3001NSButton\u30af\u30e9\u30b9\u306ekeyEquivalent\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3048\u3070\u3001\u30dc\u30bf\u30f3\u306b\u7570\u306a\u308b\u30ad\u30fc\u7b49\u4fa1\u3092\u5272\u308a\u5f53\u3066\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/li>\n<li>NSButton\u30af\u30e9\u30b9\u306etag\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3046\u3068\u3001\u623b\u308a\u5024\u3092\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/li>\n<\/ul>\n<h2>3.\u30bd\u30fc\u30b9<\/h2>\n<pre class=\"prettyprint\">enum ButtonTag: Int {\n\tcase Ok = 100\n\tcase Cancel = 200\n}\n\n@IBAction func convert(_ sender: Any) {\n\tlet alert = NSAlert()\n\n\talert.alertStyle = NSAlert.Style.warning\n\talert.messageText = \"\u5909\u63db\u3057\u3066\u3088\u308d\u3057\u3044\u3067\u3059\u304b\uff1f\"\n\talert.informativeText = \"\u30d5\u30a1\u30a4\u30eb\u3092\u5909\u63db\u3057\u307e\u3059\"\n\talert.icon = NSImage(named: NSImage.computerName)\n\t\n        let ok = alert.addButton(withTitle: \"Ok\")\n\tok.image = NSImage(named: NSImage.actionTemplateName)\n\tok.imagePosition = NSControl.ImagePosition.imageLeft\n\tok.tag = ButtonTag.Ok.rawValue\n\n\tlet cancel = alert.addButton(withTitle: \"Cancel\")\n\tcancel.tag = ButtonTag.Cancel.rawValue\n\n\t\/\/ alert.runModal()\n\talert.beginSheetModal(for: self.view.window!, completionHandler: { response in\n\t    switch response.rawValue\n\t    {\n\t        case ButtonTag.Ok.rawValue:\n\t\t    print(\"OK\")\n\t\t    break\n\t\tcase ButtonTag.Cancel.rawValue:\n\t\t    print(\"Cancel\")\n\t\t    break\n\t\tdefault:\n\t\t    print(\"invalid\")\n\t    }\n\t})\n}\n<\/pre>\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Storyboard + Swift\u3067macOS\u30a2\u30d7\u30ea\u306e\u5b66\u7fd2\u3002 NSAlert\u3067\u30c0\u30a4\u30a2\u30ed\u30b0\u30dc\u30c3\u30af\u30b9\u3092\u8868\u793a\u3055\u305b\u308b\u3002 1.\u30b9\u30bf\u30a4\u30eb \u30a2\u30e9\u30fc\u30c8\u3092\u30b7\u30fc\u30c8\u3068\u3057\u3066\u8868\u793a\u3059\u308b\u306b\u306f\u3001beginSheetModal(for:completi [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1532,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"sns_share_botton_hide":"","vkExUnit_sns_title":"","_vk_print_noindex":"","sitemap_hide":"","_veu_custom_css":"","veu_display_promotion_alert":"","vkexunit_cta_each_option":"","footnotes":""},"categories":[170,127,126],"tags":[169,179,130,129],"class_list":["post-1533","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cocoa","category-swift","category-xcode","tag-cocoa","tag-nsalert","tag-swift","tag-xcode"],"veu_head_title_object":{"title":"","add_site_title":""},"_links":{"self":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1533","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=1533"}],"version-history":[{"count":5,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1533\/revisions"}],"predecessor-version":[{"id":1539,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1533\/revisions\/1539"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/media\/1532"}],"wp:attachment":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=1533"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=1533"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=1533"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}