{"id":190846,"date":"2022-11-26T19:41:54","date_gmt":"2022-11-26T11:41:54","guid":{"rendered":"https:\/\/www.idc.net\/help\/190846\/"},"modified":"2022-11-26T19:41:54","modified_gmt":"2022-11-26T11:41:54","slug":"%e5%90%8e%e6%b5%aa%e4%ba%91ios%e6%95%99%e7%a8%8b%ef%bc%9a%e4%b8%ba%e4%bd%a0%e7%9a%84-mac-app-%e9%80%89%e6%8b%a9%e4%b8%80%e4%b8%aa%e7%94%a8%e6%88%b7%e7%95%8c%e9%9d%a2%e4%b9%a0%e6%83%af%e7%94%a8","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/190846\/","title":{"rendered":"\u540e\u6d6a\u4e91IOS\u6559\u7a0b\uff1a\u4e3a\u4f60\u7684 Mac App \u9009\u62e9\u4e00\u4e2a\u7528\u6237\u754c\u9762\u4e60\u60ef\u7528\u6cd5"},"content":{"rendered":"<h2> \u6982\u89c8 <\/h2>\n<p> \u7528 Mac Catalyst \u6784\u5efa\u7684 Mac App \u53ef\u4ee5\u4f7f\u7528 <code>UIUserInterfaceIdiom.pad<\/code><span><\/span> \u6216 <code>UIUserInterfaceIdiom.mac<\/code><span><\/span> \u7528\u6237\u754c\u9762\u4e60\u60ef\u7528\u6cd5\u8fd0\u884c\u3002\u8981\u9009\u62e9 App \u8fd0\u884c\u65f6\u7684\u4e60\u60ef\u7528\u6cd5\uff0c\u8bf7\u5728 Xcode \u9879\u76ee\u4e2d\u6253\u5f00 Mac Catalyst\uff0c\u7136\u540e\u4ece\u4ee5\u4e0b\u9009\u9879\u4e2d\u8fdb\u884c\u9009\u62e9\uff1a <\/p>\n<dl>\n<dt>\n   Scale Interface to Match iPad (\u7f29\u653e\u754c\u9762\u4ee5\u5339\u914d iPad)\n <\/dt>\n<dd>\n<p> \u4f7f\u7528 <code>UIUserInterfaceIdiom.pad<\/code><span><\/span> \u4e60\u60ef\u7528\u6cd5\u8fd0\u884c\u4f60\u7684 App\u3002\u9009\u62e9\u8fd9\u4e2a\u9009\u9879\u53ef\u4ee5\u5feb\u901f\u5c06\u4f60\u7684 iPad App \u79fb\u690d\u5230 Mac\u3002 <\/p>\n<\/dd>\n<dt>\n   Optimize Interface for Mac (\u9488\u5bf9 Mac \u4f18\u5316\u754c\u9762)\n <\/dt>\n<dd>\n<p> \u4f7f\u7528 <code>UIUserInterfaceIdiom.mac<\/code><span><\/span> \u4e60\u60ef\u7528\u6cd5\u8fd0\u884c\u4f60\u7684 App\u3002\u9009\u62e9\u8fd9\u4e2a\u9009\u9879\u53ef\u4ee5\u663e\u793a\u5916\u89c2\u548c\u884c\u4e3a\u4e0e AppKit \u4e2d\u63a7\u4ef6\u76f8\u4f3c\u7684\u63a7\u4ef6\u3002 <\/p>\n<\/dd>\n<\/dl>\n<p> \u6ce8\u91ca <\/p>\n<p> \u8981\u8fdb\u4e00\u6b65\u4e86\u89e3\u5982\u4f55\u5728 Xcode \u9879\u76ee\u4e2d\u6253\u5f00 Mac Catalyst\uff0c\u8bf7\u53c2\u9605\u201c\u4e3a\u4f60\u7684 iPad App \u521b\u5efa Mac \u7248\u672c\u201d\u3002 <\/p>\n<\/p>\n<h3> \u9996\u5148\u4ece iPad \u4e60\u60ef\u7528\u6cd5\u5f00\u59cb <\/h3>\n<p> \u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cXcode \u4f1a\u5728\u4f60\u6253\u5f00 Mac Catalyst \u540e\u9009\u62e9\u201cScale Interface to Match iPad\u201d(\u7f29\u653e\u754c\u9762\u4ee5\u5339\u914d iPad)\u3002\u8fd9\u4e2a\u9009\u9879\u63d0\u4f9b\u4e86\u4e00\u79cd\u5c06 iPad App \u79fb\u690d\u5230 Mac \u7684\u7b80\u5316\u65b9\u6cd5\u3002\u4f60\u7684 Mac App \u4f1a\u4f7f\u7528 <code>UIUserInterfaceIdiom.pad<\/code><span><\/span> \u4e60\u60ef\u7528\u6cd5\u8fd0\u884c\uff0c\u8fd9\u65f6 macOS \u4f1a\u7f29\u653e App \u7684\u7528\u6237\u754c\u9762\u4ee5\u5339\u914d Mac \u663e\u793a\u73af\u5883\uff0c\u540c\u65f6\u4fdd\u7559\u7c7b\u4f3c iPad \u4e0a\u7684\u5916\u89c2\u548c\u89c6\u56fe\u6307\u6807\u3002 <\/p>\n<p> \u5728\u6d4b\u8bd5\u4f60\u7684 App \u65f6\uff0c\u4f60\u53ef\u80fd\u4f1a\u53d1\u73b0\uff0c\u91c7\u7528\u5916\u89c2\u548c\u884c\u4e3a\u4e0e AppKit \u4e2d\u63a7\u4ef6\u76f8\u4f3c\u7684\u63a7\u4ef6\uff0c\u6216\u662f\u63d0\u4f9b\u66f4\u6e05\u6670\u7684\u6587\u672c\uff0c\u53ef\u4ee5\u63d0\u5347\u4f60 App \u7684\u7528\u6237\u4f53\u9a8c\u3002\u5982\u679c\u662f\u8fd9\u6837\uff0c\u8bf7\u9009\u62e9\u201cOptimize Interface for Mac\u201d(\u9488\u5bf9 Mac \u4f18\u5316\u754c\u9762) \u4ee5\u66f4\u6539\u4e3a <code>UIUserInterfaceIdiom.mac<\/code><span><\/span>\u3002\u4f46\u662f\uff0c\u9009\u62e9\u8fd9\u4e2a\u9009\u9879\u53ef\u80fd\u9700\u8981\u4f60\u5bf9 App \u8fdb\u884c\u5176\u4ed6\u66f4\u6539\u3002 <\/p>\n<h3> \u66f4\u65b0\u4f60\u7684 App \u4ee5\u4f7f\u7528 Mac \u4e60\u60ef\u7528\u6cd5 <\/h3>\n<p> \u9009\u62e9\u201cOptimize Interface for Mac\u201d(\u9488\u5bf9 Mac \u4f18\u5316\u754c\u9762) \u610f\u5473\u7740\u4f60\u7684 Mac App \u4f1a\u4f7f\u7528 <code>UIUserInterfaceIdiom.mac<\/code><span><\/span> \u7528\u6237\u754c\u9762\u4e60\u60ef\u7528\u6cd5\u8fd0\u884c\uff0c\u8fd9\u4f1a\u66f4\u6539\u4f60 App \u7684\u754c\u9762\u3002\u4e00\u4e9b\u63a7\u4ef6\u7684\u5c3a\u5bf8\u548c\u5916\u89c2\u4f1a\u6539\u53d8\uff0c\u800c\u4e0e\u5b83\u4eec\u7684\u4ea4\u4e92\u4f53\u9a8c\u548c\u4f7f\u7528 AppKit \u63a7\u4ef6\u65f6\u5b8c\u5168\u76f8\u540c\u3002\u4f8b\u5982\uff0c<code>UIButton<\/code><span><\/span> \u7684\u5916\u89c2\u4e0e <code>NSButton<\/code><span><\/span> \u5b8c\u5168\u76f8\u540c\u3002 <\/p>\n<p> \u7531\u4e8e\u7cfb\u7edf\u4f1a\u5728\u7528\u6237\u754c\u9762\u4e60\u60ef\u7528\u6cd5\u4e3a <code>UIUserInterfaceIdiom.mac<\/code><span><\/span> \u65f6\u9002\u5f53\u5730\u8bbe\u7f6e\u63a7\u4ef6\u5c3a\u5bf8\uff0c\u56e0\u6b64\u4e0d\u518d\u9700\u8981\u7f29\u653e\u4f60 App \u7684\u754c\u9762\u4ee5\u5339\u914d Mac \u5c4f\u5e55\u5c3a\u5bf8\u3002\u5c4f\u5e55\u70b9\u7684\u5c3a\u5bf8\u4e0e\u57fa\u4e8e AppKit \u7684 App \u4e2d\u5b8c\u5168\u76f8\u540c\u3002\u4f46\u662f\uff0c\u5982\u679c\u4f60\u7684 App \u91c7\u7528\u786c\u7f16\u7801\u5c3a\u5bf8\u6216\u4f7f\u7528\u5c3a\u5bf8\u9002\u7528\u4e8e iPad \u7684\u56fe\u50cf\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u66f4\u65b0 App \u4ee5\u9002\u5e94\u5c3a\u5bf8\u5dee\u5f02\u3002\u4f60\u53ef\u80fd\u8fd8\u9700\u8981\u8c03\u6574\u81ea\u52a8\u5e03\u5c40\u7ea6\u675f\u3002 <\/p>\n<p> \u4e00\u4e9b\u63a7\u4ef6\u63d0\u4f9b\u4e86\u5176\u4ed6\u8bbe\u7f6e\uff0c\u53ef\u5e2e\u52a9\u4f60\u5b9e\u73b0\u66f4\u50cf Mac \u7684\u5916\u89c2\u3002\u4f8b\u5982\uff0c\u5f53\u4e60\u60ef\u7528\u6cd5\u4e3a <code>UIUserInterfaceIdiom.mac<\/code><span><\/span> \u65f6\uff0c\u901a\u8fc7\u5c06 <code>preferredStyle<\/code><span><\/span> \u8bbe\u7f6e\u4e3a <code>UISwitch.Style.checkbox<\/code><span><\/span>\uff0c\u53ef\u4ee5\u4f7f <code>UISwitch<\/code><span><\/span> \u663e\u793a\u4e3a\u590d\u9009\u6846\u3002\u7136\u540e\uff0c\u5c06 <code>title<\/code><span><\/span> \u8bbe\u7f6e\u4e3a\u590d\u9009\u6846\u7684\u6587\u672c\u3002 <\/p>\n<pre><code><span><span><\/span> <span><span>let<\/span> showFavoritesAtTop <span>=<\/span> <span>UISwitch<\/span>()<\/span><\/span><span><span><\/span> <span>showFavoritesAtTop.preferredStyle <span>=<\/span> .checkbox<\/span><\/span><span><span><\/span> <span><span>if<\/span> traitCollection.userInterfaceIdiom <span>==<\/span> .mac {<\/span><\/span><span><span><\/span> <span> showFavoritesAtTop.title <span>=<\/span> <span>\"Always show favorite recipes at the top\"<\/span><\/span><\/span><span><span><\/span> <span>}<\/span><\/span><\/code>\n<\/pre>\n<p> <code>UIPageControl<\/code><span><\/span>\u3001<code>UIRefreshControl<\/code><span><\/span> \u548c <code>UIStepper<\/code><span><\/span> \u4e0d\u9002\u7528\u4e8e\u91c7\u7528 Mac \u4e60\u60ef\u7528\u6cd5\u8fd0\u884c\u7684 App\u3002\u5982\u679c\u4f60\u5c1d\u8bd5\u5728\u89c6\u56fe\u4e2d\u663e\u793a\u8fd9\u4e9b\u63a7\u4ef6\uff0c\u4f60\u7684 App \u4f1a\u629b\u51fa\u5f02\u5e38\u3002\u5f53\u7528\u6237\u754c\u9762\u4e60\u60ef\u7528\u6cd5\u4e3a <code>UIUserInterfaceIdiom.mac<\/code><span><\/span> \u65f6\uff0c\u8bf7\u7528\u76f8\u4f3c\u7684\u529f\u80fd\u66ff\u6362\u8fd9\u4e9b\u63a7\u4ef6\u3002\u4f8b\u5982\uff0c\u7528\u201c\u5237\u65b0\u201d\u83dc\u5355\u9879\u66ff\u6362 <code>UIRefreshControl<\/code><span><\/span>\uff0c\u65b9\u6cd5\u662f\u521b\u5efa\u4e00\u4e2a\u6807\u9898\u4e3a\u201cRefresh\u201d\u4e14\u4f7f\u7528\u952e\u76d8\u5feb\u6377\u952e Command-R \u7684 <code>UIKeyCommand<\/code><span><\/span> \u5bf9\u8c61\u3002\u7136\u540e\uff0c\u5c06\u8fd9\u4e00\u547d\u4ee4\u6dfb\u52a0\u5230 App \u7684\u83dc\u5355\u7cfb\u7edf\u4e2d\u3002\u6709\u5173\u66f4\u591a\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605\u201c\u5411\u83dc\u5355\u680f\u548c\u7528\u6237\u754c\u9762\u4e2d\u6dfb\u52a0\u83dc\u5355\u548c\u5feb\u6377\u952e<span><\/span>\u201d\u3002 <\/p>\n<\/p>\n<h3> \u786e\u5b9a\u5f53\u524d\u7684\u7528\u6237\u754c\u9762\u4e60\u60ef\u7528\u6cd5 <\/h3>\n<p> \u8981\u786e\u5b9a\u4f60\u7684 App \u662f\u4e0d\u662f\u5728\u4f7f\u7528 Mac \u4e60\u60ef\u7528\u6cd5\u8fd0\u884c\uff0c\u8bf7\u5c06 <code>userInterfaceIdiom<\/code><span><\/span> \u5c5e\u6027\u7684\u503c\u4e0e <code>UIUserInterfaceIdiom.mac<\/code><span><\/span> \u8fdb\u884c\u6bd4\u8f83\u3002\u5f53\u6bd4\u8f83\u7ed3\u679c\u4e3a <code>true<\/code><span><\/span> \u65f6\uff0c\u4f60\u53ef\u4ee5\u9488\u5bf9 Mac \u91cf\u8eab\u5b9a\u5236 App \u7684\u884c\u4e3a\uff0c\u4f8b\u5982\uff0c\u663e\u793a\u4e00\u4e2a\u4e0d\u540c\u7684\u5b50\u89c6\u56fe\u3002 <\/p>\n<pre><code><span><span><\/span> <span><span>let<\/span> childViewController: <span>UIViewController<\/span><\/span><\/span><span><span><\/span> <span><span>if<\/span> traitCollection.userInterfaceIdiom <span>==<\/span> .mac {<\/span><\/span><span><span><\/span> <span> childViewController <span>=<\/span> <span>MacOptimizedChildViewController<\/span>()<\/span><\/span><span><span><\/span> <span>} <span>else<\/span> {<\/span><\/span><span><span><\/span> <span> childViewController <span>=<\/span> <span>ChildViewController<\/span>()<\/span><\/span><span><span><\/span> <span>}<\/span><\/span><span><span><\/span> <span>addChild(childViewController)<\/span><\/span><span><span><\/span> <span>childViewController.view.frame <span>=<\/span> view.bounds<\/span><\/span><span><span><\/span> <span>view.addSubview(childViewController.view)<\/span><\/span><span><span><\/span> <span>childViewController.didMove(toParent: <span>self<\/span>)<\/span><\/span><\/code>\n<\/pre>\n<\/p>\n<h3> \u8bbe\u7f6e\u9996\u9009\u884c\u4e3a\u98ce\u683c <\/h3>\n<p> \u91c7\u7528 Mac \u4e60\u60ef\u7528\u6cd5\u65f6\uff0c\u4e00\u4e9b\u63a7\u4ef6 (\u4f8b\u5982 <code>UIButton<\/code><span><\/span> \u548c <code>UISlider<\/code><span><\/span>) \u7684\u5916\u89c2\u4e0e\u5176\u5bf9\u5e94 AppKit \u63a7\u4ef6\u5b8c\u5168\u76f8\u540c\u3002\u4f46\u662f\uff0c\u5728\u4e00\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4f60\u53ef\u80fd\u5e0c\u671b\u5728 App \u4e2d\u5229\u7528 Mac \u4e60\u60ef\u7528\u6cd5\uff0c\u800c\u540c\u65f6\u4fdd\u7559\u63a7\u4ef6\u7684 iPad \u5916\u89c2\u548c\u884c\u4e3a\u3002\u4f8b\u5982\uff0c\u8ba9 iPad App \u663e\u793a\u5e26\u6709\u81ea\u5b9a\u62c7\u6307\u56fe\u50cf\u7684\u6ed1\u5757\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u5f53\u7528\u6237\u754c\u9762\u4e60\u60ef\u7528\u6cd5\u4e3a <code>UIUserInterfaceIdiom.mac<\/code><span><\/span> \u65f6\uff0c\u7528 Mac Catalyst \u6784\u5efa\u7684 Mac \u7248 App \u4f1a\u663e\u793a\u4e00\u4e2a\u6807\u51c6\u7684 macOS \u6ed1\u5757\u3002 <\/p>\n<p> \u8981\u5728 App \u7684 iPad \u548c Mac \u7248\u672c\u4e2d\u63d0\u4f9b\u4e00\u81f4\u5916\u89c2\u7684\u6ed1\u5757\uff0c\u8bf7\u5c06\u8be5\u6ed1\u5757\u7684 <code>preferredBehavioralStyle<\/code><span><\/span> \u8bbe\u7f6e\u4e3a <code>UIBehavioralStyle.pad<\/code><span><\/span>\u3002\u8bbe\u7f6e\u8fd9\u79cd\u884c\u4e3a\u98ce\u683c\u540e\uff0c\u6ed1\u5757\u7684\u884c\u4e3a\u65b9\u5f0f\u5c31\u4f1a\u50cf\u7528\u6237\u754c\u9762\u4e60\u60ef\u7528\u6cd5\u662f <code>UIUserInterfaceIdiom.pad<\/code><span><\/span> \u65f6\u4e00\u6837\uff0c\u5373\u4f7f\u8be5 App \u4f7f\u7528\u7684\u662f Mac \u4e60\u60ef\u7528\u6cd5\u4e5f\u662f\u5982\u6b64\u3002 <\/p>\n<p> \u8bf7\u8bb0\u4f4f\uff0c\u5f53 App \u4f7f\u7528 Mac \u4e60\u60ef\u7528\u6cd5\u65f6\uff0cmacOS \u4e0d\u4f1a\u7f29\u653e App \u754c\u9762\uff0c\u56e0\u6b64\uff0c\u5373\u4f7f\u9996\u9009\u884c\u4e3a\u98ce\u683c\u662f <code>UIBehavioralStyle.pad<\/code><span><\/span>\uff0c\u4f60\u53ef\u80fd\u4e5f\u9700\u8981\u66f4\u65b0\u4f60\u7684 App \u4ee5\u9002\u5e94\u5c3a\u5bf8\u5dee\u5f02\u3002\u4f8b\u5982\uff0c\u5e26\u6709\u81ea\u5b9a\u62c7\u6307\u56fe\u50cf\u7684\u6ed1\u5757\u5728 Mac App \u4e2d\u4e0e\u5728 iPad App \u4e2d\u53ef\u80fd\u9700\u8981\u4e0d\u540c\u5c3a\u5bf8\u7684\u56fe\u50cf\u3002 <\/p>\n<pre><code><span><span><\/span> <span><span>let<\/span> slider <span>=<\/span> <span>UISlider<\/span>()<\/span><\/span><span><span><\/span> <span>slider.minimumValue <span>=<\/span> <span>0<\/span><\/span><\/span><span><span><\/span> <span>slider.maximumValue <span>=<\/span> <span>1<\/span><\/span><\/span><span><span><\/span> <span>slider.value <span>=<\/span> <span>0.5<\/span><\/span><\/span><span><span><\/span> <span>slider.preferredBehavioralStyle <span>=<\/span> .pad<\/span><\/span><span><span><\/span> <span> <\/span><\/span><span><span><\/span> <span><span>if<\/span> slider.traitCollection.userInterfaceIdiom <span>==<\/span> .mac {<\/span><\/span><span><span><\/span> <span> slider.setThumbImage(<span>#imageLiteral<\/span>(resourceName: <span>\"customSliderThumbMac\"<\/span>), for: .normal)<\/span><\/span><span><span><\/span> <span>} <span>else<\/span> {<\/span><\/span><span><span><\/span> <span> slider.setThumbImage(<span>#imageLiteral<\/span>(resourceName: <span>\"customSliderThumb\"<\/span>), for: .normal)<\/span><\/span><span><span><\/span> <span>}<\/span><\/span><\/code>\n<\/pre>\n<p> \u5f53\u884c\u4e3a\u98ce\u683c\u4e3a <code>UIBehavioralStyle.mac<\/code><span><\/span> \u65f6\uff0c<code>UIButton<\/code><span><\/span> \u548c <code>UISlider<\/code><span><\/span> \u7684\u4e00\u4e9b\u5c5e\u6027\u548c\u65b9\u6cd5\u5728 Mac \u4e60\u60ef\u7528\u6cd5\u4e2d\u4e0d\u53d7\u652f\u6301\uff0c\u8c03\u7528\u5b83\u4eec\u65f6\u4f1a\u629b\u51fa\u5f02\u5e38\uff1b\u4f8b\u5982\uff0c\u4e3a\u9664 <code>normal<\/code><span><\/span> \u4ee5\u5916\u7684\u4efb\u4f55\u63a7\u4ef6\u72b6\u6001\u8bbe\u7f6e\u6309\u94ae\u7684\u6807\u9898\u6216\u56fe\u50cf\uff0c\u4ee5\u53ca\u8bbe\u7f6e\u6ed1\u5757\u7684\u62c7\u6307\u56fe\u50cf\u3001\u6700\u5c0f\u6216\u6700\u5927\u8f68\u8ff9\u56fe\u50cf\u3001\u8272\u8c03\u6216\u503c\u56fe\u50cf\u3002\u4f46\u662f\uff0c\u5f53\u63a7\u4ef6\u7684\u884c\u4e3a\u98ce\u683c\u4e3a <code>UIBehavioralStyle.pad<\/code><span><\/span> \u65f6\uff0c\u8fd9\u4e9b\u5c5e\u6027\u548c\u65b9\u6cd5\u53ef\u4ee5\u5728 Mac \u4e60\u60ef\u7528\u6cd5\u4e2d\u4f7f\u7528\u3002 <\/p>\n<h3> \u63d0\u4f9b\u4e0d\u540c\u7684\u4ee3\u7801\u8def\u5f84 <\/h3>\n<p> \u5373\u4f7f\u4f60\u7684 Mac App \u4f7f\u7528 <code>UIUserInterfaceIdiom.pad<\/code><span><\/span> \u4e60\u60ef\u7528\u6cd5\u8fd0\u884c\uff0c\u4f60\u53ef\u80fd\u4e5f\u9700\u8981\u66f4\u6539 Mac App \u7684\u5916\u89c2\u6216\u884c\u4e3a\u3002\u4f7f\u7528 <code>targetEnvironment()<\/code> \u7f16\u8bd1\u6761\u4ef6\u6839\u636e\u76ee\u6807\u73af\u5883\u9009\u62e9\u4e0d\u540c\u7684\u4ee3\u7801\u8def\u5f84\u3002 <\/p>\n<p> \u4f8b\u5982\uff0c\u5982\u679c\u4f60\u7684 iPad App \u4f1a\u5728\u5220\u9664\u6309\u94ae\u65c1\u8fb9\u4ee5\u5f39\u51fa\u7a97\u53e3\u5f62\u5f0f\u663e\u793a\u9879\u76ee\u5220\u9664\u786e\u8ba4\uff0c\u4f46\u4f60\u60f3\u5728 Mac App \u4e2d\u4ee5\u63d0\u9192\u5f62\u5f0f\u663e\u793a\u8be5\u786e\u8ba4\uff0c\u5219\u53ef\u4ee5\u6dfb\u52a0\u4e00\u4e2a <code>targetEnvironment()<\/code> \u6761\u4ef6\u6765\u786e\u5b9a\u63d0\u9192\u63a7\u5236\u5668\u7684\u9996\u9009\u98ce\u683c\u3002 <\/p>\n<pre><code><span><span><\/span> <span><span>let<\/span> deleteAction <span>=<\/span> <span>UIAlertAction<\/span>(title: <span>\"Delete\"<\/span>, style: .destructive) { (action) <span>in<\/span><\/span><\/span><span><span><\/span> <span> <span>if<\/span> dataStore.delete(recipe) {<\/span><\/span><span><span><\/span> <span> <span>self<\/span>.recipe <span>=<\/span> <span>nil<\/span><\/span><\/span><span><span><\/span> <span> }<\/span><\/span><span><span><\/span> <span>}<\/span><\/span><span><span><\/span> <span> <\/span><\/span><span><span><\/span> <span><span>let<\/span> cancelAction <span>=<\/span> <span>UIAlertAction<\/span>(title: <span>\"Cancel\"<\/span>, style: .cancel, handler: <span>nil<\/span>)<\/span><\/span><span><span><\/span> <span> <\/span><\/span><span><span><\/span> <span><span>#if<\/span> targetEnvironment(macCatalyst)<\/span><\/span><span><span><\/span> <span><span>let<\/span> preferredStyle <span>=<\/span> <span>UIAlertController<\/span>.<span>Style<\/span>.alert<\/span><\/span><span><span><\/span> <span><span>#else<\/span><\/span><\/span><span><span><\/span> <span><span>let<\/span> preferredStyle <span>=<\/span> <span>UIAlertController<\/span>.<span>Style<\/span>.actionSheet<\/span><\/span><span><span><\/span> <span><span>#endif<\/span><\/span><\/span><span><span><\/span> <span> <\/span><\/span><span><span><\/span> <span><span>let<\/span> alert <span>=<\/span> <span>UIAlertController<\/span>(title: <span>\"Are you sure you want to delete <span>\\(recipe.title)<\/span>?\"<\/span>, message: <span>nil<\/span>, preferredStyle: preferredStyle)<\/span><\/span><span><span><\/span> <span>alert.addAction(deleteAction)<\/span><\/span><span><span><\/span> <span>alert.addAction(cancelAction)<\/span><\/span><span><span><\/span> <span> <\/span><\/span><span><span><\/span> <span><span>if<\/span> <span>let<\/span> popoverPresentationController <span>=<\/span> alert.popoverPresentationController {<\/span><\/span><span><span><\/span> <span> popoverPresentationController.barButtonItem <span>=<\/span> sender <span>as?<\/span> <span>UIBarButtonItem<\/span><\/span><\/span><span><span><\/span> <span>}<\/span><\/span><span><span><\/span> <span> <\/span><\/span><span><span><\/span> <span>present(alert, animated: <span>true<\/span>, completion: <span>nil<\/span>)<\/span><\/span><\/code>\n<\/pre><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6982\u89c8 \u7528 Mac Catalyst \u6784\u5efa\u7684 Mac App \u53ef\u4ee5\u4f7f\u7528 UIUserInterfaceIdiom [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[189686],"tags":[],"class_list":["post-190846","post","type-post","status-publish","format-standard","hentry","category-ios"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/190846","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/comments?post=190846"}],"version-history":[{"count":0,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/190846\/revisions"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=190846"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=190846"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=190846"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}