{"id":786,"date":"2023-05-17T08:05:36","date_gmt":"2023-05-17T07:05:36","guid":{"rendered":"https:\/\/www.renaudpradenc.com\/?p=786"},"modified":"2023-05-17T08:05:36","modified_gmt":"2023-05-17T07:05:36","slug":"xcode-tips","status":"publish","type":"post","link":"https:\/\/www.renaudpradenc.com\/?p=786","title":{"rendered":"Xcode tips"},"content":{"rendered":"\n<p>Time to be productive with Xcode!<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Define your own shortcuts<\/h3>\n\n\n\n<p>If there&#8217;s only one thing to remember from this post, that is to define your own keyboard shortcuts. I find that some handy shortcuts are associated with commands that are seldom used. Working with a French keyboard I also need to change some defaults anyway.<\/p>\n\n\n\n<p>So go to Xcode &gt; Settings &gt; Key Bindings and experiment.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.renaudpradenc.com\/wp-content\/uploads\/2023\/05\/XcodeKeyBindings.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"729\" src=\"https:\/\/www.renaudpradenc.com\/wp-content\/uploads\/2023\/05\/XcodeKeyBindings-1024x729.png\" alt=\"\" class=\"wp-image-796\" srcset=\"https:\/\/www.renaudpradenc.com\/wp-content\/uploads\/2023\/05\/XcodeKeyBindings-1024x729.png 1024w, https:\/\/www.renaudpradenc.com\/wp-content\/uploads\/2023\/05\/XcodeKeyBindings-300x214.png 300w, https:\/\/www.renaudpradenc.com\/wp-content\/uploads\/2023\/05\/XcodeKeyBindings-768x547.png 768w, https:\/\/www.renaudpradenc.com\/wp-content\/uploads\/2023\/05\/XcodeKeyBindings-1536x1094.png 1536w, https:\/\/www.renaudpradenc.com\/wp-content\/uploads\/2023\/05\/XcodeKeyBindings-1200x855.png 1200w, https:\/\/www.renaudpradenc.com\/wp-content\/uploads\/2023\/05\/XcodeKeyBindings.png 1884w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Move between subwords<\/h3>\n\n\n\n<p>You probably know \u2325\u2190 and \u2325\u2192 to move from one word to the other. But did you know ^\u2190 and ^\u2192 to move between subwords? Extremy useful with CamelCase symbols.<br><em>macOS might already use the same shortcuts to navigate between Spaces of Mission Control (I favorise Xcode).<\/em><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Missing text commands<\/h3>\n\n\n\n<p>I&#8217;m desperate with Xcode still missing some commands that are widely available in other text editors. At last, and after begging for 15 years, Xcode 14 can finally duplicate a line (\u2318D)! But I still see too many people using their mouse to select a whole line of code.<\/p>\n\n\n\n<p>Look for the TextPlus Xcode extension on the Mac AppStore and install it. Now assign the following keyboard shortcuts:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>Copy line<\/td><td>^C<\/td><\/tr><tr><td>Cut line<\/td><td>^X<\/td><\/tr><tr><td>Clear line<\/td><td>^\u2326<\/td><\/tr><tr><td>Clear line and Paste<\/td><td>^V<\/td><\/tr><tr><td>Duplicate Line Up<\/td><td>\u2325\u21e7\u2191<\/td><\/tr><tr><td>Duplicate Line Down<\/td><td>\u2325\u21e7\u2193<\/td><\/tr><tr><td>Insert Line Above<\/td><td>^\u2325\u2191<\/td><\/tr><tr><td>Insert Line Below<\/td><td>^\u2325\u2193<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\">Keyboard shortcuts associated with TextPlus commands<\/figcaption><\/figure>\n\n\n\n<p>Then you can copy\/cut\/paste\/delete a whole line of code without selecting it. Unfortunately not with \u2318C \/ \u2318X \/ \u2318V.<\/p>\n\n\n\n<p>I adopted the same keyboard shortcuts than Visual Studio code to duplicate lines.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Show Document Items<\/h3>\n\n\n\n<p>This command is misnamed but you probably already know it. It&#8217;s the little menu that pops-up when you click the &#8220;Breadcrumb&#8221; bar.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.renaudpradenc.com\/wp-content\/uploads\/2023\/05\/XcodeBreadcrumb.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"206\" src=\"https:\/\/www.renaudpradenc.com\/wp-content\/uploads\/2023\/05\/XcodeBreadcrumb-1024x206.png\" alt=\"Xcode: the Document breadcrumb\" class=\"wp-image-793\" srcset=\"https:\/\/www.renaudpradenc.com\/wp-content\/uploads\/2023\/05\/XcodeBreadcrumb-1024x206.png 1024w, https:\/\/www.renaudpradenc.com\/wp-content\/uploads\/2023\/05\/XcodeBreadcrumb-300x60.png 300w, https:\/\/www.renaudpradenc.com\/wp-content\/uploads\/2023\/05\/XcodeBreadcrumb-768x154.png 768w, https:\/\/www.renaudpradenc.com\/wp-content\/uploads\/2023\/05\/XcodeBreadcrumb-1536x308.png 1536w, https:\/\/www.renaudpradenc.com\/wp-content\/uploads\/2023\/05\/XcodeBreadcrumb-2048x411.png 2048w, https:\/\/www.renaudpradenc.com\/wp-content\/uploads\/2023\/05\/XcodeBreadcrumb-1200x241.png 1200w, https:\/\/www.renaudpradenc.com\/wp-content\/uploads\/2023\/05\/XcodeBreadcrumb-1980x398.png 1980w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>First: did you know that you could type to filter it ?<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><a href=\"https:\/\/www.renaudpradenc.com\/wp-content\/uploads\/2023\/05\/DocumentItemsFiltered.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.renaudpradenc.com\/wp-content\/uploads\/2023\/05\/DocumentItemsFiltered.png\" alt=\"Xcode: Filtering the Document items list\" class=\"wp-image-794\" width=\"400\" height=\"332\" srcset=\"https:\/\/www.renaudpradenc.com\/wp-content\/uploads\/2023\/05\/DocumentItemsFiltered.png 730w, https:\/\/www.renaudpradenc.com\/wp-content\/uploads\/2023\/05\/DocumentItemsFiltered-300x249.png 300w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/><\/a><\/figure><\/div>\n\n\n<p>And now is the second trick: the Xcode command which corresponds to this menu is &#8220;Show Document Items&#8221;. Associate it with a very accessible keyboard shortcut, for example the key on the top left of your keyboard. That will be \u2318` on a US keyboard or \u2318@ on my French keyboard.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Vim mode<\/h3>\n\n\n\n<p>You may activate the <em>Editor &gt; Vim mode<\/em> if you&#8217;re that kind of person. There are no <em>Visual<\/em> or <em>Block<\/em> modes, which I don&#8217;t care much for, but I do miss relative line numbering.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Tests shortcuts<\/h3>\n\n\n\n<p>Use \u21e7\u2318U to build the current test target.<\/p>\n\n\n\n<p>Use ^\u2325\u21e7U to launch the current test class.<\/p>\n\n\n\n<p>Use ^\u2325\u2318G to relaunch the last test (very useful when writing a test).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Test counterpart<\/h3>\n\n\n\n<p>Say you&#8217;re editing MyFile.swift. Press ^\u2318\u2191 (Navigate > Jump to Next Counterpart) twice to go to MyFileTests.swift.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Snippets<\/h3>\n\n\n\n<p>Create snippets for extracts of code which are frequent, hard to type or hard to remember.<\/p>\n\n\n\n<p>To create a snippet, select some code then <em>Editor > Create code snippet<\/em>. Use &lt;#placeholder#> where appropriate.<\/p>\n\n\n\n<p>Here are some of my favourite snippets for Swift:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>Code<\/strong><\/td><td><strong>Completion keyword<\/strong><\/td><\/tr><tr><td><code>guard let self else { return }<\/code><\/td><td><code>guards<\/code><\/td><\/tr><tr><td><code>@testable import MyApp<\/code><\/td><td><code>myapp<\/code><\/td><\/tr><tr><td><code>\/\/\/ :inheritdoc:<\/code><\/td><td><code>inherit<\/code><\/td><\/tr><tr><td><code>\/\/ MARK: &lt;#mark#><\/code><\/td><td><code>mark<\/code><\/td><\/tr><tr><td><code>\/\/\/ :nodoc:<\/code><\/td><td><code>nodoc<\/code><\/td><\/tr><tr><td><code>\/\/ swiftlint:disable:this &lt;#rule#><\/code><\/td><td><code>lintdis<\/code><\/td><\/tr><tr><td><code>\/\/ swiftlint:enable &lt;#rule#><\/code><\/td><td><code>linten<\/code><\/td><\/tr><tr><td><code>[weak self]<\/code><\/td><td><code>weaks<\/code><\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\">My favourite snippets for Swift<\/figcaption><\/figure>\n\n\n\n<p> <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Time to be productive with Xcode! Define your own shortcuts If there&#8217;s only one thing to remember from this post, that is to define your own keyboard shortcuts. I find that some handy shortcuts are associated with commands that are seldom used. Working with a French keyboard I also need to change some defaults anyway. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-786","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.renaudpradenc.com\/index.php?rest_route=\/wp\/v2\/posts\/786","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.renaudpradenc.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.renaudpradenc.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.renaudpradenc.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.renaudpradenc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=786"}],"version-history":[{"count":15,"href":"https:\/\/www.renaudpradenc.com\/index.php?rest_route=\/wp\/v2\/posts\/786\/revisions"}],"predecessor-version":[{"id":805,"href":"https:\/\/www.renaudpradenc.com\/index.php?rest_route=\/wp\/v2\/posts\/786\/revisions\/805"}],"wp:attachment":[{"href":"https:\/\/www.renaudpradenc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=786"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.renaudpradenc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=786"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.renaudpradenc.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=786"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}