<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Zdeněk Topič</title>
    <description>The latest articles on DEV Community by Zdeněk Topič (@zdnk).</description>
    <link>https://dev.to/zdnk</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F90122%2Fcc745d00-73b0-48ba-86e3-7e585bc59d5e.jpeg</url>
      <title>DEV Community: Zdeněk Topič</title>
      <link>https://dev.to/zdnk</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/zdnk"/>
    <language>en</language>
    <item>
      <title>Swift Tip: Initializing &amp; configuring properties</title>
      <dc:creator>Zdeněk Topič</dc:creator>
      <pubDate>Wed, 08 Aug 2018 08:51:39 +0000</pubDate>
      <link>https://dev.to/zdnk/swift-tip-initializing--configuring-properties-227d</link>
      <guid>https://dev.to/zdnk/swift-tip-initializing--configuring-properties-227d</guid>
      <description>&lt;p&gt;&lt;strong&gt;This article is also published &lt;a href="https://blg.zdnkt.com/swift-tip-initializing-configuring-properties/"&gt;on my blog&lt;/a&gt;.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Sometimes, you need to do more than just assign a value to a property on initialization.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="kt"&gt;Foo&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;formatter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;DateFormatter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You might need to configure some of the properties. The first thing that comes to your mind is probably doing it in an initializer.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="kt"&gt;Foo&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;formatter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;DateFormatter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="nf"&gt;init&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;formatter&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dateStyle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;short&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are more ways how to configure your properties without putting the code in the initializer.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="kt"&gt;Foo&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;formatter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;DateFormatter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$0&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dateStyle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;short&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$0&lt;/span&gt;
    &lt;span class="p"&gt;}(&lt;/span&gt;&lt;span class="kt"&gt;DateFormatter&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above, you can see that the property &lt;code&gt;Foo.formatter&lt;/code&gt; is constructed with a closure which takes the instance of &lt;code&gt;DateFormatter&lt;/code&gt; as a parameter. You can do the same with initializing the &lt;code&gt;DateFormatter&lt;/code&gt; directly in the closure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="kt"&gt;Foo&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;formatter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;DateFormatter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;formatter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;DateFormatter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="n"&gt;formatter&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dateStyle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;short&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;formatter&lt;/span&gt;
    &lt;span class="p"&gt;}()&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also use a function or a static method to construct the property.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="kd"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;dateFormatter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;DateFormatter&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;formatter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;DateFormatter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;formatter&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dateStyle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;short&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;formatter&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="kt"&gt;Foo&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;formatter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;DateFormatter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;dateFormatter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="kt"&gt;Foo&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;formatter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;DateFormatter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;Foo&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dateFormatter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kd"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;dateFormatter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;DateFormatter&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;formatter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;DateFormatter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="n"&gt;formatter&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dateStyle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;short&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;formatter&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All these options work for local variables too.&lt;/p&gt;

&lt;p&gt;Get in touch on &lt;a href="https://twitter.com/zdnkt"&gt;Twitter @zdnkt&lt;/a&gt; for comments, discussion feedback or ideas!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This article is also published &lt;a href="https://blg.zdnkt.com/swift-tip-initializing-configuring-properties/"&gt;on my blog&lt;/a&gt;.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>swift</category>
      <category>xcode</category>
      <category>ios</category>
      <category>development</category>
    </item>
    <item>
      <title>📺 Fullscreen Xcode and Simulator</title>
      <dc:creator>Zdeněk Topič</dc:creator>
      <pubDate>Wed, 08 Aug 2018 08:48:19 +0000</pubDate>
      <link>https://dev.to/zdnk/-fullscreen-xcode-and-simulator-42ng</link>
      <guid>https://dev.to/zdnk/-fullscreen-xcode-and-simulator-42ng</guid>
      <description>&lt;p&gt;The way you are switching between the apps, virtual desktops or fullscreen apps affects your workflow, efficiency, and focus. I have a tip how to run Xcode 9 or 10 with Simulator in a divided fullscreen mode so you can focus on the development without distractions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This article is also published on &lt;a href="https://blg.zdnkt.com/fullscreen-xcode-and-simulator/" rel="noopener noreferrer"&gt;my blog&lt;/a&gt;.&lt;/strong&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  ☹️ The problem
&lt;/h1&gt;

&lt;p&gt;I don't know about you, but I actually like (a lot) working with Xcode, or with any other IDE (and different apps) in fullscreen. It gives me the full usage of the screen and I can become easily more productive in the app. Also switching between 2 or more apps is easier thanks to macOS gestures. But there is one thing that used to be an issue for me. It was debugging an application. You have 2 options:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Real device&lt;/li&gt;
&lt;li&gt;or Simulator&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;With the real device, you have to pick it up all the time, probably even unlock it for Xcode to be able to run the application. That's annoying. I used this approach for years because I was thinking "there's nothing like device", later I've got a little smarter and started using Simulator for most of my testing and debugging. It went fine, but had some pain points:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;every time I had to switch with a gesture to Simulator (and back)&lt;/li&gt;
&lt;li&gt;when Xcode hit breakpoint or app crashed, macOS transitioned me back to Xcode&lt;/li&gt;
&lt;li&gt;you could not look at the app and check console output at the same time&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After a while a realized it bothers me, it is not productive and I lost focus many times.&lt;/p&gt;

&lt;h1&gt;
  
  
  ✅ The Solution
&lt;/h1&gt;

&lt;p&gt;An 💡 idea popped in my head, why don't I put it next to Xcode in fullscreen? Unfortunately, Simulator does not support fullscreen mode by default. I did a little research and figured there's a way, but that's not all we need, if we had Simulator running in one fullscreen and Xcode in second, it wouldn't almost any improvement. We need to merge them together to run in divided fullscreen mode. And luckily, that's enabled for both once they support fullscreen.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblg.zdnkt.com%2Fcontent%2Fimages%2F2018%2F08%2FScreenshot-2018-08-02-at-20.27.34.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblg.zdnkt.com%2Fcontent%2Fimages%2F2018%2F08%2FScreenshot-2018-08-02-at-20.27.34.png" alt="Xcode 10 with Simulator in fullscreen"&gt;&lt;/a&gt;&lt;br&gt;
On the left side is Xcode 10 beta 5 running in fullscreen and on the right side we have Simulator running iPhone X with iOS 12.&lt;/p&gt;
&lt;h1&gt;
  
  
  💨 The easy way
&lt;/h1&gt;

&lt;p&gt;To enable the fullscreen mode in Simulator, just open up Terminal app and &lt;strong&gt;run the following command&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;defaults write com.apple.iphonesimulator AllowFullscreenMode -bool YES
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;That's it!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you want to checkout other settings (the options are in the screenshot below) you can change in Simulator, keep reading and follow the steps.&lt;/p&gt;

&lt;h1&gt;
  
  
  📐 More customizations
&lt;/h1&gt;

&lt;p&gt;If you want to do this for &lt;strong&gt;Xcode 9&lt;/strong&gt;, then you are fine and &lt;strong&gt;it is all you need&lt;/strong&gt;. However, if you are already using &lt;strong&gt;Xcode 10&lt;/strong&gt;, you &lt;strong&gt;need both versions&lt;/strong&gt; of Xcode (9 and 10) to make it work.&lt;/p&gt;

&lt;p&gt;Apple has hidden features and settings all over the system and their apps. Some of those you can access when you have a directory called &lt;code&gt;AppleInternal&lt;/code&gt; in the root of your main volume.&lt;/p&gt;

&lt;h2&gt;
  
  
  ❓ What is &lt;code&gt;/AppleInternal&lt;/code&gt;?
&lt;/h2&gt;

&lt;p&gt;AFAIK it is empty directory Apple engineers use to enable development and debug features, menus, and settings. When you create the directory, a bunch of &lt;code&gt;Internal&lt;/code&gt; menus might appear across different apps, I recommend to ignore it unless you know what are you doing. We will use it to enable the fullscreen mode for Simulator app.&lt;/p&gt;

&lt;h2&gt;
  
  
  👣 Steps
&lt;/h2&gt;

&lt;p&gt;Let's get to it then!&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Check if you need to disable SIP
&lt;/h3&gt;

&lt;p&gt;Just &lt;strong&gt;try&lt;/strong&gt; to do &lt;strong&gt;step 3&lt;/strong&gt;. If it works, continue with step 4 to the end. &lt;strong&gt;In case it fails&lt;/strong&gt; with message &lt;code&gt;mkdir: /AppleInternal: Operation not permitted&lt;/code&gt;, &lt;strong&gt;go to step 2&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Disable SIP
&lt;/h3&gt;

&lt;p&gt;SIP is &lt;a href="https://support.apple.com/en-us/HT204899" rel="noopener noreferrer"&gt;System Integrity Protection&lt;/a&gt; introduced in El Capitan. It protects you from viruses and in many cases even from yourself 😜. We need to disable it because &lt;code&gt;/AppleInternal&lt;/code&gt; is one of those protected areas.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;restart your computer and hold &lt;code&gt;⌘ CMD + R&lt;/code&gt; until your Mac reboots to Recovery mode&lt;/li&gt;
&lt;li&gt;in top menu select &lt;code&gt;Utilities &amp;gt; Terminal&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;run &lt;code&gt;csrutil disable&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;restart it again using the  menu&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Create &lt;code&gt;/AppleInternal&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;You should be able to create &lt;code&gt;/AppleInternal&lt;/code&gt; now.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;open Terminal app&lt;/li&gt;
&lt;li&gt;execute &lt;code&gt;sudo mkdir /AppleInternal&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4. Enjoy the music 🎉
&lt;/h3&gt;

&lt;p&gt;Open the Simulator app thru Xcode 9 (&lt;code&gt;Xcode &amp;gt; Open Developer Tool &amp;gt; Simulator&lt;/code&gt;). In the menu, you should now see a new item, &lt;code&gt;Internal&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblg.zdnkt.com%2Fcontent%2Fimages%2F2018%2F08%2FScreenshot-2018-08-02-at-22.40.32.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblg.zdnkt.com%2Fcontent%2Fimages%2F2018%2F08%2FScreenshot-2018-08-02-at-22.40.32.png" alt="Simulator internal settings"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Just go ahead and have a play with it. Don't forget to enable fullscreen mode (&lt;code&gt;Internal &amp;gt; Allow Fullscreen Mode&lt;/code&gt;). The changes you make in Xcode 9 Simulator should be also reflected in Xcode 10 Simulator even if it does not show the &lt;code&gt;Internal&lt;/code&gt; menu.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Enable SIP
&lt;/h3&gt;

&lt;p&gt;When you are finished with your modifications, repeat step 2, but instead of running &lt;code&gt;csrutil disable&lt;/code&gt;, &lt;strong&gt;run &lt;code&gt;csrutil enable&lt;/code&gt;&lt;/strong&gt; to be safe again.&lt;/p&gt;

&lt;p&gt;I hope you were successful and enjoy the fullscreen mode!&lt;/p&gt;

&lt;p&gt;Please feel free to reach me on &lt;a href="https://twitter.com/zdnkt" rel="noopener noreferrer"&gt;Twitter @zdnkt&lt;/a&gt; for comments, feedback, ideas and discussion.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This article is also published on &lt;a href="https://blg.zdnkt.com/fullscreen-xcode-and-simulator/" rel="noopener noreferrer"&gt;my blog&lt;/a&gt;.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>xcode</category>
      <category>swift</category>
      <category>objectivec</category>
      <category>simulator</category>
    </item>
  </channel>
</rss>
