<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Marko Benacic on Medium]]></title>
        <description><![CDATA[Stories by Marko Benacic on Medium]]></description>
        <link>https://medium.com/@marko.benacic?source=rss-72f790f8e4e5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*h_OPzdhx9ZO79JjVZvv7HA.jpeg</url>
            <title>Stories by Marko Benacic on Medium</title>
            <link>https://medium.com/@marko.benacic?source=rss-72f790f8e4e5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 05:53:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@marko.benacic/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Making your life easier with Xcode shortcuts, snippets and templates]]></title>
            <link>https://medium.com/arasdigitalproducts/making-your-life-easier-with-xcode-shortcuts-snippets-and-templates-9f44496a67b1?source=rss-72f790f8e4e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/9f44496a67b1</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[mobile-development]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[xcode]]></category>
            <dc:creator><![CDATA[Marko Benacic]]></dc:creator>
            <pubDate>Tue, 06 Dec 2022 13:41:49 GMT</pubDate>
            <atom:updated>2022-12-06T13:41:49.066Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cjm1LJFt0sDnUnUgfwCumQ.png" /></figure><h3>Making your life easier with Xcode snippets, shortcuts, and templates</h3><h4>Tips and tricks to make you a more productive iOS developer — Part 1</h4><p>Typing a lot of code and smashing that mechanical keyboard a bunch surely can be satisfying. But at the same time, we can all agree that writing boilerplate code takes up a big chunk of our precious time. Since every self-respecting developer strives to be as efficient as possible, it is important to master the tools provided by Apple’s <em>Xcode</em> if you wish to take your productivity to the next level.</p><p>This article is part 1 of a three-part series about X<em>code’s</em> snippets, shortcuts, and templates. <a href="https://medium.com/codablestudio">Part 2<strong> </strong>— <em>Xcode </em>Shortcuts</a> and <a href="https://medium.com/codablestudio">part 3 — <em>Xcode </em>Templates</a> are coming soon so make sure to come back and check on them!</p><h3>#Snippets</h3><p>Snippets are X<em>code’s</em> tool used for creating templates of frequently used boilerplate code. You have probably been using snippets without even knowing about them! For example, if you start typing func, you will see a suggestion like the one in the picture:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/479/0*QrwCMyy1nUqDZWV2" /></figure><p>If you then proceed to hit <strong>enter</strong>, X<em>code</em> will generate a skeleton where you can easily input function name, parameters, return type, and a function body. Once you’ve filled in a field (also known as<em> placeholder token)</em>, you can press <strong>tab</strong> to switch to another one like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/519/1*Tv0jAiWdvCF7jn_TE7EVpw.gif" /></figure><h3>#How to find snippets</h3><p>You can find available snippets in 3 ways:</p><ul><li>Using the keyboard shortcut command (<strong>⌘</strong>) + shift(<strong>⇧</strong>) + L</li><li>Using the bar menu on the top: <strong>View -&gt; Show library</strong></li><li>Pressing the + button at the top right</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/231/0*w6rjS_V-8TU8G3ep" /><figcaption>Open snippets button</figcaption></figure><p>After you’ve found the one you want to use, you can press <strong>enter</strong> or drag and drop it into your code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/683/1*-j_KuUIZd8jaGYMVOVpKhQ.gif" /></figure><p>There are many useful predetermined snippets already included such as <em>docatch, guardlet, ifelse, available</em>,<em> </em>etc. Feel free to look around the library and try incorporating the ones you think would be the most useful to you.</p><h3>#Adding your own snippet</h3><p>Here comes the useful part. Let’s say you’re writing a lot of closures that are using references to <strong>self</strong>. One way of avoiding <a href="https://www.swiftbysundell.com/questions/is-weak-self-always-required/">retain cycles</a> is by using [weak self]. If we then wish to use that <em>self</em> reference in our closure, we must first make sure the reference even exists (that it is not <strong>nil</strong>). One way of doing that is by using guard: guard let self = self else { return }.</p><p>Here’s an example:</p><pre><strong>class</strong> ViewController: UIViewController {</pre><pre><strong>   private</strong> <strong>var</strong> someText: String = &quot;Peanut butter&quot;</pre><pre><strong>   override</strong> <strong>func</strong> viewDidLoad() {<br><strong>      super</strong>.viewDidLoad()<br>      <br>      <strong>let</strong> someClosure = { [<strong>weak</strong> <strong>self</strong>] <strong>in<br>         guard</strong> <strong>let</strong> self = <strong>self</strong> <strong>else</strong> { <strong>return</strong> }<br>         self.someText = &quot;bananas&quot;<br>      }<br>      print(someText)<br>      someClosure()<br>      print(someText)<br>   }</pre><pre>}</pre><p>Output:</p><pre>Peanut butter<br>Bananas</pre><p>Since we are probably going to repeat those two little lines of code lots of times throughout our apps, let’s create two snippets for them:</p><p>Highlight [weak self]with your mouse -&gt; <strong>right click</strong> -&gt; <strong>Create code snippet</strong>.</p><p>Change the title to <em>Weak self</em> and in completion write “ws” like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*_E_6LYlMZApODIruc_omwQ.png" /></figure><p>There are some other options to set for our snippet such as changing the preferred language (any language that is supported by X<em>code</em>), platform (iOS, macOS, tvOS, watchOS, or All), and scope availability, as well. Feel free to test them out!</p><p>If we now proceed to write our shortcut (in this case “ws”), code completion will keep suggesting our snippet and pressing <strong>enter</strong> will write it out for us. Now we do the same procedure for the next line of code containing <strong>guard let self</strong>.</p><p>Using our newly created snippets should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/523/1*H8__w4He2uXcVozSsHmvOg.gif" /></figure><p>Wow! That was fast!!</p><h3>#Placeholder tokens</h3><p>I often use mark comments (and so should you!) to help me read through my code better.</p><p>To create a mark comment snippet with a <em>placeholder token </em>just type your placeholder name (eg. <em>content</em>) between &lt;# and #&gt; in your code, and create a snippet as shown above.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/514/1*DXQ2PEPhPtQtJ5bYB4OoAg.gif" /></figure><h3>#Sharing your snippets</h3><p>What if you want to share your super cool snippet with a friend? All of your snippets are located at ~/Library/Developer/Xcode/UserData/CodeSnippets. They are saved as <em>plist</em> file format and you can copy and paste them directly into the CodeSnippets folder at the file path shown above. Unfortunately, they are given a random UUID name, but you can simply open them with a text editor to find the one you want to share.</p><h3>#That’s all…</h3><p>Congrats! You’ve successfully created your first code snippet and made yourself a more efficient iOS developer!</p><p>In the next part of this mini-series, we will share more about using the best <a href="https://medium.com/codablestudio"><em>Xcode </em>shortcuts that can help you become an even more efficient iOS developer</a>.</p><p>If you liked this article, check out our <a href="https://codable.studio/">website</a> for more content!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9f44496a67b1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/arasdigitalproducts/making-your-life-easier-with-xcode-shortcuts-snippets-and-templates-9f44496a67b1">Making your life easier with Xcode shortcuts, snippets and templates</a> was originally published in <a href="https://medium.com/arasdigitalproducts">Aras™ Digital Products</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>