<?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 Manuel Kunz on Medium]]></title>
        <description><![CDATA[Stories by Manuel Kunz on Medium]]></description>
        <link>https://medium.com/@kunz.manuelk?source=rss-f15a5f8ee217------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*eR08RcivhZT2lqkmbE3_OQ.png</url>
            <title>Stories by Manuel Kunz on Medium</title>
            <link>https://medium.com/@kunz.manuelk?source=rss-f15a5f8ee217------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 03:10:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kunz.manuelk/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[Pie Chart in SwiftUI]]></title>
            <link>https://medium.com/stepup-development/pie-chart-in-swiftui-24a9ec44d438?source=rss-f15a5f8ee217------2</link>
            <guid isPermaLink="false">https://medium.com/p/24a9ec44d438</guid>
            <category><![CDATA[developer]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Manuel Kunz]]></dc:creator>
            <pubDate>Sat, 03 Apr 2021 09:41:40 GMT</pubDate>
            <atom:updated>2021-04-09T20:06:47.863Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W873X-xOLf83H6YALXyoLQ.jpeg" /></figure><p>Recently two friends and I were participating in a <a href="https://swiftuijam.com/">SwiftUI Jam</a>. Over one weekend we were developing a little application in SwiftUI, which was a lot of fun.</p><p>The dashboard of the application shows multiple statistics, one of them presented as a pie chart.</p><p>In the following I want to show you the approach we took to make a simple reusable pie chart in SwiftUI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XYyR4v-_TCwiKHm2Pkoy9Q.png" /></figure><p>At first I’m going to show you how to make a pie chart with fixed values to get the hang on how the slices are drawn. Further into the article I will show you our approach on making the pie chart easier to use and responsive in its size.</p><h3><strong>Drawing a circle</strong></h3><p>Drawing a circle in SwiftUI could not be easier.</p><pre>Circle()</pre><p>That’s it, but this will not take us far, so what we really need is drawing a slice of a pie in every size we want. So first, let’s take a look on how to draw for example a half circle. For this we are going to use paths.</p><p>I’m not going to show you how paths in general work, but with paths and arcs you can draw much more complex forms than circles.</p><h4><strong>Draw a half circle</strong></h4><p>The following code creates a half circle with a radius of 100 from degree 0 to degree 180.</p><p><em>.move</em> moves the path to the correct starting point. <em>.addArc</em> draws an arc around the given center between the two angles with the given radius.</p><p>This is all you need to draw a half circle.</p><pre>Path { path in<br>    path.move(to: CGPoint(x: 200, y: 200))<br>    path.addArc(center: CGPoint(x: 200, y: 200), <br>                radius: 100, <br>                startAngle: Angle(degrees: 0), <br>                endAngle: Angle(degrees: 180), <br>                clockwise: false)<br>}<br>.fill(Color.red)</pre><p>What sometimes can be a little bit tricky, at least it was for me, is the meaning of clockwise.</p><p>In the official <a href="https://developer.apple.com/documentation/uikit/uibezierpath/1624358-init#1965853">Apple Documentation</a> you can see an image of a circle to understand which degree is at which position of the circle. Clockwise is defined as ‘<strong>The direction in which to draw the arc</strong>’. So one, like me, would think of a clock we all know and would expect the code in the example above with clockwise false to draw an half circle with the top half filled red, but it is the complete opposite, you will get the lower half of the circle. It is a little bit confusing and might clash with the way SwiftUI handles coordinate systems as explained in this <a href="https://stackoverflow.com/a/57226474/7804792">answer</a> by <a href="https://stackoverflow.com/users/77567/rob-mayoff">rob-mayoff</a>.</p><p>For the following this will not be relevant because we will just work with what is given to us. I will choose clockwise as false, I’m sure this can also be done with clockwise true, but you will have to adjust the calculation later on.</p><h3><strong>Draw a Pie Chart with fixed values</strong></h3><p>But before we get to fancy calculations let’s draw our first pie chart.</p><pre>ZStack(alignment: .center) {<br>    Path { path in<br>        path.addArc(center: CGPoint(x: 200, y: 200), <br>                    radius: 100,<br>                    startAngle: Angle(degrees: 0), <br>                    endAngle: Angle(degrees: 180), <br>                    clockwise: false)<br>    }<br>    .fill(Color.red)</pre><pre>    Path { path in<br>        path.addArc(center: CGPoint(x: 200, y: 200), <br>                    radius: 100, <br>                    startAngle: Angle(degrees: 180), <br>                    endAngle: Angle(degrees: 360), <br>                    clockwise: false)<br>    }<br>    .fill(Color.blue)<br>}</pre><p>We put the <em>Path</em> from the example in a <em>ZStack</em> to place multiple elements above each other and adjusted the start and end <em>Angle</em> for the second <em>Path</em>, this results in a pie chart with two halfs.</p><p>For fixed values this is all you would need, but in most cases the values shown are not fixed so let’s have a look at how we can handle this.</p><h4><strong>Simplify the UI</strong></h4><p>Our pie chart will exist of multiple slices, I ended up calling them a <em>PieSlice</em>. In the example above each <em>Path</em> is one <em>PieSlice</em>, so we will wrap this in a struct:</p><pre>private struct PieSlice : Hashable {<br>    var start: Angle<br>    var end: Angle<br>    var color: Color<br>}</pre><p>In the body of the view, we can now iterate (that’s why we need the <em>PieSlice</em> to perform to <em>Hashable</em>) the pie slices, remove the fixed angles and the color.</p><pre>struct PieChart: View {<br>    private var slices = [<br>        PieSlice(start: Angle(degrees: 0), <br>                 end: Angle(degrees: 180), <br>                 color: .red),<br>        PieSlice(start: Angle(degrees: 180), <br>                 end: Angle(degrees: 360), <br>                 color: .blue)<br>    ]</pre><pre>    var body: some View {<br>        ZStack(alignment: .center) {<br>            ForEach(slices, id: \.self) { slice in<br>                Path { path in<br>                    path.move(to: CGPoint(x: 200, y: 200))<br>                    path.addArc(center: CGPoint(x: 200, y: 200),              <br>                                radius: 100, <br>                                startAngle: slice.start, <br>                                endAngle: slice.end, <br>                                clockwise: false<br>                    )<br>                }<br>                .fill(slice.color)<br>            }<br>        }<br>    }<br>}</pre><pre>private struct PieSlice : Hashable {<br>    var start: Angle<br>    var end: Angle<br>    var color: Color<br>}</pre><p>The pie chart can now easily be extended with more slices. The fixed values of radius and the center point will removed later on, we will now do some calculations to get rid off the fixed angles.</p><h3><strong>Calculation</strong></h3><p>When creating some kind of reusable component the saying of ‘<strong>Eat your own dog food</strong>’ always comes up to my mind. So I want to make my pie charts as easy to use as possible. The minimum of information we have to provide are the values and the color in which a value should be displayed (if the colors can be random you could also come up with some predefined colors or a RandomColorGenerator).</p><pre>init(_ values: [(Color, Double)]) {<br>    slices = calculateSlices(from: values)<br>}</pre><pre>// Usage for the example above</pre><pre>PieChart([<br>    (.red, 50),<br>    (.blue, 50)<br>])</pre><p>This is where our calculation has to come in. We have the given values that should be displayed and we need to convert these values into our slices. This will be done in the <em>calculateSlices </em>function.</p><pre>private func calculateSlices(from inputValues: [(color: Color, value: Double)]) -&gt; [PieSlice] {</pre><pre>    // 1<br>    let sumOfAllValues = inputValues.reduce(0) { $0 + $1.value }</pre><pre>    guard sumOfAllValues &gt; 0 else {<br>        return []<br>    }</pre><pre>    let degreeForOneValue = 360.0 / sumOfAllValues</pre><pre>    // 2<br>    var slices = [PieSlice]()<br>    var currentStartAngle = 0.0<br>    inputValues.forEach { inputValue in<br>        let endAngle = degreeForOneValue * inputValue.value + <br>                       currentStartAngle</pre><pre>        slices.append(<br>                 PieSlice(<br>                     start: Angle(degrees: currentStartAngle),  <br>                     end: Angle(degrees: endAngle), <br>                     color: inputValue.color<br>                 )<br>        )</pre><pre>        currentStartAngle = endAngle<br>    }<br>    return slices<br>}</pre><p>This might seem a bit complex at first but let’s break it down. <br>In the first section two calculations are done.</p><p>First we get the sum of all values. We will then devide 360.0 degrees by this sum.<br>This will give us the degrees which are needed to display a single value.</p><p>For example the input values are 20, 30 and 50. The sum of this values are 100.</p><pre>let degreeForOneValue = 360.0 / 100<br>// Will be 3.6</pre><p>In this example we will need 3.6 degrees to display the value 1. For 50 we will need <strong>3,6 * 50</strong> which is <strong>180</strong> this will take half of the circle.</p><p>In the second section of the calculation we iterate the input values and map them to pie slices. Additional to the conversion of value to degree we have to handle the start of each angle. Each <em>PieSlice</em> should start at the end angle of the previous <em>PieSlice</em>, this is handled with the <em>currentStartAngle</em> which will be added to each calculated end angle. At the end of each iteration the <em>currentStartAngle</em> will be set to the <em>endAngle</em> of the calculated <em>PieSlice</em>.</p><p>This is all we have to do to create a pie chart which is pretty simple to use. The example above with two half circles can now be achieved like this:</p><pre>PieChart([<br>    (.red, 50),<br>    (.blue, 50),<br>])</pre><pre>// or this</pre><pre>PieChart([<br>    (.red, 1),<br>    (.blue, 1),<br>])</pre><p>We can now create any pie chart. But we are not finished yet, our pie chart is dynamic in values but it is pretty fixed in its size with a hard coded center point and a radius which is fixed to 100.</p><h3><strong>Responsive size for the Pie Chart</strong></h3><p>We can get the size of the parent view by wrapping the <em>ZStack</em> into a <em>GeometryReader</em>. Our pie chart will be placed in some view, so it will be some kind of rectangle. This rectangle can have a different height and width in which we want to use as much space without overlapping.</p><p>So what do we need? First the center of the rectangle. Second the radius the pie chart can have to fit into the rectangle.</p><p>The center is the half of the width for x and the half of the height for y. These values can be accessed on the <em>GeometryReader</em>.</p><p>The height and width of the rectangle are most likely not the same value, except a square, we have to use the smaller of both values as radius, the pie chart then has the biggest size possible without overlapping.</p><pre>GeometryReader { reader in<br>    let halfWidth = (reader.size.width / 2)<br>    let halfHeight = (reader.size.height / 2)<br>    let radius = min(halfWidth, halfHeight)<br>    let center = CGPoint(x: halfWidth, y: halfHeight)</pre><pre>    ZStack(alignment: .center) {<br>        ForEach(slices, id: \.self) { slice in<br>            Path { path in<br>                path.move(to: center)<br>                path.addArc(center: center, <br>                            radius: radius, <br>                            startAngle: slice.start, <br>                            endAngle: slice.end, <br>                            clockwise: false<br>                )<br>            }<br>            .fill(slice.color)<br>        }<br>    }<br>}</pre><p>And that’s it. I’d love to hear any kind of feedback.</p><p>The example project can be found on <a href="https://github.com/KunzManuel/SwiftUI-PieChart">GitHub</a>. Show me what kind of reusable Views have you done with SwiftUI?</p><p>I hope you liked the article, the approach we chose and the way the pie chart can be used.</p><p>Feel free to contact me <a href="https://twitter.com/manuelkunz_sw">Twitter</a>.</p><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=24a9ec44d438" width="1" height="1" alt=""><hr><p><a href="https://medium.com/stepup-development/pie-chart-in-swiftui-24a9ec44d438">Pie Chart in SwiftUI</a> was originally published in <a href="https://medium.com/stepup-development">StepUp Development</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to use multiple users with git]]></title>
            <link>https://medium.com/stepup-development/how-to-use-multiple-users-with-git-5962e689b5f0?source=rss-f15a5f8ee217------2</link>
            <guid isPermaLink="false">https://medium.com/p/5962e689b5f0</guid>
            <category><![CDATA[git]]></category>
            <category><![CDATA[gitlab]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[github]]></category>
            <dc:creator><![CDATA[Manuel Kunz]]></dc:creator>
            <pubDate>Thu, 11 Feb 2021 16:59:14 GMT</pubDate>
            <atom:updated>2021-02-11T16:59:14.487Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*maurjo94aWjtzeoMZKkncA.jpeg" /></figure><p>Did you ever switch from a project for work to a private project and in the rush of coding you committed and pushed your code with the wrong user? Keep reading how to avoid this situation by setting up different users for different repositories.</p><p>So we are not going to start in a cage but let’s pretend we are Tony Stark and we are working on a private project and on the side we do commit for a little iron suit we are building. Let’s create the following structure of folders and files in our root directory. The <em>.gitconfig</em> file in the root directory might already exist. If not create it as well.</p><pre>├── Root/<br>│   ├── .gitconfig<br>│   ├── Private/<br>│   │   ├── .gitconfig<br>│   ├── IronMan/<br>│   │   ├── .gitconfig</pre><p>Let’s start with the the config files in our subfolders.</p><p>In the Private folder <em>~/Private/.gitconfig,</em> add the following:</p><pre>[user]<br>    name = Tony Stark<br>    email = stark.tony@starkindustries.com</pre><p>In the IronMan folder <em>~/IronMan/.gitconfig,</em> add the following:</p><pre>[user]<br>    name = Iron Man<br>    email = stark.tony@starkindustries.com</pre><p>Finally, in the <em>.gitconfig</em> in the root folder we will put all the things together.</p><pre>[user]<br>    name = Default Name<br>    email = default@mail.com</pre><pre>[includeIf &quot;gitdir:~/Private/&quot;]<br>    path = ~/Private/.gitconfig<br><br>[includeIf &quot;gitdir:~/IronMan/&quot;]<br>    path = ~/IronMan/.gitconfig</pre><p>The user here is your default user for all git configs. For all projects in IronMan the <em>~/IronMan/.gitconfig </em>will be applied and the user will be overwritten.</p><p>That’s it. You do not have to worry about commiting with the wrong user anymore. If you have any other ideas that simplify working with git let us know and give us feedback if you like to.</p><p>Enjoy coding.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5962e689b5f0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/stepup-development/how-to-use-multiple-users-with-git-5962e689b5f0">How to use multiple users with git</a> was originally published in <a href="https://medium.com/stepup-development">StepUp Development</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Write and maintain custom git commands]]></title>
            <link>https://medium.com/stepup-development/write-and-maintain-custom-git-commands-18f9077a7a0c?source=rss-f15a5f8ee217------2</link>
            <guid isPermaLink="false">https://medium.com/p/18f9077a7a0c</guid>
            <category><![CDATA[git]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[developer]]></category>
            <dc:creator><![CDATA[Manuel Kunz]]></dc:creator>
            <pubDate>Fri, 15 Jan 2021 11:25:49 GMT</pubDate>
            <atom:updated>2021-01-15T11:25:49.951Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RpdCB8ssHVk6dpHL31rKbA.jpeg" /></figure><p>Git is a version control system used by many developers all around the globe. It has a lot of functionalities and you might, like me, not always remember everything you can do with it.</p><h3>Create a remote branch</h3><p>Let’s dive into it with an example that shows how to create and work with branches.</p><pre>$ git branch feature/stepup-blog</pre><p>The branch command will create a local branch only and not push it to the remote. This is pretty straightforward and the syntax is not very hard to remember.<br>But when I do create a new branch most of the times I want to switch to this branch immediately, so I have to checkout the branch I just created.</p><pre>$ git checkout feature/stepup-blog</pre><p>Next you are writing some code and it comes to the point you commit and push your changes. Remember, we are just working locally, so if you want to push your changes, git will tell you the following.</p><pre>fatal: The current branch feature/stepup-blog has no upstream branch.<br>To push the current branch and set the remote as upstream, use</pre><pre>git push --set-upstream origin feature/stepup-blog</pre><p>This basically speaks for itself, your branch has no upstream branch and it even tells you how to set this upstream branch.<br>Of course this is not the hardest git workflow that exists but it still annoys me after several times. What I like to do is create a little custom git command which execute these steps in one command, so I do not have to do all of these steps each time I create a new branch.</p><p>To maintain your git commands I suggest you create your own git repository where you can place your commands in. This enables you to track changes and share your custom commands.</p><p>I am using <a href="https://www.zsh.org/">zsh</a> so in my .zshrc file in my home directory, I added the following line to add the path to my repository to the PATH variable.</p><pre>PATH=&quot;$PATH:/Users/mkunz/Private/git-commands&quot;</pre><h3><strong>Now let’s create our first custom git command</strong></h3><p>We are going to create a command which creates a branch, switches to this branch and pushes the branch to the remote. <br>Later we want to use this command like any other git command and call it like this.</p><pre>$ git rbranch feature/stepup-blog</pre><p>In this case rbranch stands for remote branch but you can name the command whatever you like. So we need to create a file and make it executable. Make sure you are at the root directory of your repository and create the file git-&lt;commandName&gt;. I choose rbranch as the command name so I have to name the file git-rbranch.</p><pre>$ touch git-rbranch<br>$ chmod +x git-rbranch</pre><p>To find out if this works, open the file and add the following lines.</p><pre>#!/bin/bash<br>echo &quot;Hello world&quot;</pre><p>The first line tells Unix that the file is to be executed by /bin/bash. The following command will print <em>Hello World</em>.</p><p>Save it and now you can call your git command like the standard git commands you know.</p><pre>$ git rbranch<br>// Hello World</pre><p>This is all you need for your setup.</p><h3>Add functionality to the command</h3><p>And now let’s get back to the workflow we had in the beginning and create a new remote branch.<br>A git command is similar to a shell script so we can pass arguments to it and access these arguments.<br>So we just take the steps we have and place them in our command, the parameter can be accessed by <em>$1 </em>referring to the first parameter (<em>$0</em> points to the location of the command).</p><pre>#!/bin/bash</pre><pre>git branch $1<br>git checkout $1<br>git push --set-upstream origin $1</pre><p>And that is pretty much all you have to do.</p><p>I really like to make even simple workflows a little bit simpler. For example a <a href="https://github.com/KunzManuel/git-commands/blob/main/git-cleanup">git command that deletes local branches which are no longer available on the remote</a>. Maybe a git command which automatically adds your commit message to your changelog? <br>I have a <a href="https://github.com/KunzManuel/git-commands">repository</a> on GitHub with, at the moment, just a few git commands. <br>Feel free to contribute to the repository and share your custom git commands that you like to use. Also feel free to reach out to me on <a href="https://twitter.com/manuelkunz_sw">Twitter</a> if you have any feedback about this post.</p><p>Happy coding.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=18f9077a7a0c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/stepup-development/write-and-maintain-custom-git-commands-18f9077a7a0c">Write and maintain custom git commands</a> was originally published in <a href="https://medium.com/stepup-development">StepUp Development</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simplify your developer life with Boop]]></title>
            <link>https://medium.com/stepup-development/simplify-your-developer-life-with-boop-99356b2e8a2a?source=rss-f15a5f8ee217------2</link>
            <guid isPermaLink="false">https://medium.com/p/99356b2e8a2a</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[ios-localization]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[android-resources]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Manuel Kunz]]></dc:creator>
            <pubDate>Sun, 30 Aug 2020 11:48:38 GMT</pubDate>
            <atom:updated>2020-08-30T11:48:38.751Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*31otc8SYcU_62ljvcddsmw.jpeg" /></figure><pre>&quot;main_hero_name&quot; = &quot;Hercules&quot;;<br>&lt;string name=&quot;main_hero_name&quot;&gt;Hercules&lt;/string&gt;</pre><p>If you have ever seen this, you are probably an app developer, you have at least developed for Android and iOS and at some point you dealt with assets like localizables.</p><p>Keeping your iOS and Android localizables in sync can be hard, especially when you work in a team and your project grows. Your localizables end up being different on both platforms and it just keeps getting harder to maintain. It would be simple if you could just copy and paste those strings from one platform to the other and you could be sure that every key and value is the same. One way to do this is to use tools other people have already written for us. One of these tools is <a href="https://boop.okat.best/"><strong>Boop</strong></a>.</p><p>You can use <a href="https://boop.okat.best/"><strong>Boop</strong></a> for your daily routine of developing, e.g. format and validate your JSON file, decode and encode data, count words, sort lines and so much more. With Boop you can use one offline tool instead of 5 online tools you have to keep switching between to get your results. The best part is, you can <a href="https://github.com/IvanMathy/Boop/blob/main/Boop/Documentation/CustomScripts.md">add custom scripts</a> easily.</p><p>For the Localizable handling between iOS and Android you could use two simple scripts to convert Android to iOS Localizables and conversely.</p><h3>Android to iOS</h3><pre>/**<br>  {<br>    &quot;api&quot;:1,<br>    &quot;name&quot;:&quot;Android Strings to iOS Localizables&quot;,<br>    &quot;description&quot;:&quot;Converts Android Strings to iOS Localizables&quot;,<br>    &quot;author&quot;:&quot;Manuel Kunz&quot;,<br>    &quot;icon&quot;:&quot;quote&quot;,<br>    &quot;tags&quot;:&quot;string, android, ios&quot;<br>  }<br>**/<br><br>function main(input) {<br>    let lines = input.fullText.split(&#39;\n&#39;)<br>    var result = []<br>    lines.forEach(element =&gt; {<br>      var temp = element<br>      temp = temp.replace(&quot;&lt;string name=&quot;, &quot;&quot;)<br>      temp = temp.replace(&quot;&lt;/string&gt;&quot;, &quot;\&quot;;&quot;)<br>      temp = temp.replace(&quot;&gt;&quot;, &quot; = \&quot;&quot;)<br>      result.push(temp)      <br>    })<br>  <br>    input.fullText = result.join(&#39;\n&#39;)<br>}</pre><h3>iOS to Android</h3><pre>/**<br>  {<br>    &quot;api&quot;:1,<br>    &quot;name&quot;:&quot;iOS Localizables to Android Strings&quot;,<br>    &quot;description&quot;:&quot;Converts iOS Localizables to Android Strings&quot;,<br>    &quot;author&quot;:&quot;Manuel Kunz&quot;,<br>    &quot;icon&quot;:&quot;quote&quot;,<br>    &quot;tags&quot;:&quot;string, android, ios&quot;<br>  }<br>**/<br><br>function main(input) {<br>    let lines = input.fullText.split(&#39;\n&#39;)<br>    var result = []<br>    lines.forEach(element =&gt; {<br>      if(element !== &quot;&quot;) {<br>        var regex = /&quot;(.*?)&quot;/g<br>        var matches = [];<br>        var match = regex.exec(element);<br>        while (match != null) {<br>            matches.push(match[1]);<br>            match = regex.exec(element);<br>        }<br>        result.push(&quot;&lt;string name=\&quot;&quot; + matches[0] + &quot;\&quot;&gt;&quot; + matches[1] + &quot;&lt;/string&gt;&quot;)<br>      }      <br>    })   <br>    input.fullText = result.join(&#39;\n&#39;)<br>}</pre><p>Tools like this just help you get your work done in one place and make your developer life easier. If you have any ideas of scripts you could imagine to write and include to <a href="https://boop.okat.best/"><strong>Boop</strong></a>, feel free to share your ideas. We would like to hear from you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=99356b2e8a2a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/stepup-development/simplify-your-developer-life-with-boop-99356b2e8a2a">Simplify your developer life with Boop</a> was originally published in <a href="https://medium.com/stepup-development">StepUp Development</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Handling multiple sheets in SwiftUI]]></title>
            <link>https://medium.com/stepup-development/handling-multiple-sheets-in-swiftui-2e9a73d99cd7?source=rss-f15a5f8ee217------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e9a73d99cd7</guid>
            <category><![CDATA[development]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Manuel Kunz]]></dc:creator>
            <pubDate>Wed, 10 Jun 2020 17:14:37 GMT</pubDate>
            <atom:updated>2020-06-10T17:14:37.632Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HHpvjr0k_DW7Y9WzGSv0wg.jpeg" /></figure><p>In order for a view to be displayed modally in SwiftUI, the sheet modifier can be used. In its simplest form a sheet is being presented if a given condition is true.</p><pre>struct ContentView: View {</pre><pre>@State var presentSheet = false</pre><pre>var body: some View {<br>        VStack {<br>            Button(&quot;Show Settings&quot;) {<br>                self.presentSheet = true<br>            }<br>        }.sheet(isPresented: $presentSheet) {<br>            SettingsView()<br>        }<br>    }<br>}</pre><p>In this example, the sheet modifier is applied to the VStack. However, it could also be applied to the Button directly.</p><p>What if we wanted to display more than one sheet from a specific view, though?</p><p>The most logical choice would be to just place another sheet modifier below the existing one, since it is possible to chain modifiers as we please. Unfortunately this does not work. In order for us to be able to use multiple sheets, each modifier has to be applied to the button directly. Using two or more consecutive sheet modifiers does not work in SwiftUI, only the last sheet modifier will be applied and can be used. As a result, we could design our view like this.</p><pre>@State var showSettingsView = false<br>@State var showProfileView = false</pre><pre>var body: some View {<br>    VStack {<br>        Button(&quot;Show Settings&quot;) {<br>            self.showSettingsView = true<br>        }.sheet(isPresented: $showSettingsView) {<br>            SettingsView()<br>        }<br>        Button(&quot;Show Profile&quot;) {<br>            self.showProfileView = true<br>        }.sheet(isPresented: $showProfileView) {<br>            ProfileView()<br>        }<br>    }<br>}</pre><p>But as you can imagine in a working app, this view won’t be as compact. If you need to handle multiple different sheets, the code gets blown up very quickly. Additionally, each sheet needs its own @<em>State</em> to be presented.</p><p>To avoid <em>massive Views</em>, it would be great if there was a way to separate this navigation logic from our view into a dedicated file. There are different alternatives that simplify the handling of multiple sheet modifiers. This article shows one of them.</p><p><strong>Moving the presentation logic into an observable ViewModel</strong></p><p>First of all we are going to separate the logic of which sheet will be shown to a separate view model.</p><pre>class SheetNavigator: ObservableObject {<br>    @Published var showSettingsView = false<br>    @Published var showProfileView = false<br>}</pre><p>This <em>SheetNavigator</em> class has to conform to the <em>ObservableObject</em> protocol and will be observed by the view itself using the <em>@ObservedObject</em> property wrapper.</p><pre>@ObservedObject var sheetNavigator = SheetNavigator()<br>var body: some View {<br>    VStack {<br>        Button(&quot;Show Settings&quot;) {<br>            self.sheetNavigator.showSettingsView = true<br>        }.sheet(isPresented: self.$sheetNavigator.showSettingsView) {<br>      SettingsView()<br>        }<br>        Button(&quot;Show Profile&quot;) {<br>            self.sheetNavigator.showProfileView = true<br>        }.sheet(isPresented: self.$sheetNavigator.showProfileView) {<br>            ProfileView()<br>        }<br>    }<br>}</pre><p>After we moved our presentation state variables into the view model, the code did not really improve. The state handling is not scalable and we still have multiple sheet modifiers cluttering our view. Let‘s reduce those at first to just one sheet modifier.</p><pre>VStack {<br>    Button(&quot;Show Settings&quot;) {<br>        self.sheetNavigator.showSettingsView = true<br>    }<br>    Button(&quot;Show Profile&quot;) {<br>        self.sheetNavigator.showProfileView = true<br>    }<br>}.sheet(isPresented: ???) {<br>    ???<br>}</pre><p>At this point we only have one sheet modifier, but which view should be shown and to which state variable should we bind the sheet? The answer is our SheetNavigator.</p><pre>class SheetNavigator: ObservableObject {<br>    var showSettingsView = false<br>    var showProfileView = false<br>    @Published var showSheet = false<br>    <br>    func sheetView() -&gt; AnyView {<br>        if showFirstView {<br>            return Text(&quot;SettingsView&quot;).eraseToAnyView()<br>        } else if showSecondView {<br>            return Text(&quot;ProfileView&quot;).eraseToAnyView()<br>        }<br>        return Text(&quot;Empty&quot;).eraseToAnyView()        <br>    }<br>}</pre><pre>extension View {<br>    func eraseToAnyView() -&gt; AnyView {<br>        AnyView(self)<br>    }<br>}</pre><p>We add an additional bool state to handle the binding for all sheets. The function <em>sheetView</em> returns the View we want to show for the selected button. All this logic happens in the navigator and our view is way simpler than before.</p><p>Since we are dealing with different views that are displayed in our sheets, we have to type erase said views to AnyView. For the sake of readability, we added a little View extension to simplify wrapping a view inside of AnyView.</p><p>As there might be performance implications when using AnyView, you could also consider wrapping your views inside a <em>Group</em>.</p><pre>VStack {<br>    Button(&quot;Show Settings&quot;) {<br>        self.sheetNavigator.showSettingsView = true<br>        self.sheetNavigator.showSheet = true<br>    }<br>    Button(&quot;Show Profile&quot;) {<br>        self.sheetNavigator.showProfileView = true<br>        self.sheetNavigator.showSheet = true<br>    }    <br>}.sheet(isPresented: self.$sheetNavigator.showSheet) {<br>    self.sheetNavigator.sheetView()<br>}</pre><p>But it’s not perfect, since we need to set two different booleans in the action of a button, one for the sheet that should be shown and one for the state that is bound to the sheet modifier. Additionally, the amount of state variables required, will grow for each new sheet we want to show. Let‘s use a different approach, that is more scalable and also improves readability: Enums.</p><p><strong>Enums to the rescue!</strong></p><p>Now there is only one published parameter left, the <em>showSheet</em> state that is bound to the sheet modifier. For the different sheet views we want to present, we added a <em>SheetDestination</em> enum.</p><pre>class SheetNavigator: ObservableObject {</pre><pre>@Published var showSheet = false<br>    var sheetDestination: SheetDestination = .none<br>    <br>    enum SheetDestination {<br>        case none<br>        case settings<br>        case profile<br>    }<br>    <br>  func sheetView() -&gt; AnyView {<br>      switch sheetDestination {<br>      case .none:<br>          return Text(&quot;None&quot;).eraseToAnyView()<br>      case .settings:<br>          return SettingsView().eraseToAnyView()<br>      case .profile:<br>          return ProfileView().eraseToAnyView()<br>      }<br>  }<br>}</pre><p>With these changes the View will now look like this.</p><pre>@ObservedObject var sheetNavigator = SheetNavigator()<br>var body: some View {<br>    VStack {<br>        Button(&quot;Show Settings&quot;) {<br>            self.sheetNavigator.sheetDestination = .settings<br>            self.sheetNavigator.showSheet = true<br>        }<br>        Button(&quot;Show Profile&quot;) {<br>            self.sheetNavigator.sheetDestination = .profile<br>            self.sheetNavigator.showSheet = true<br>        }<br>    }.sheet(isPresented: self.$sheetNavigator.showSheet) {<br>        self.sheetNavigator.sheetView()<br>    }<br>}</pre><p>At this point, we are still calling <em>showSheet</em> ourselves. Actually, setting the <em>sheetDestination</em> should really be enough. So we remove setting <em>showSheet</em> to true from the view and handle this with a property observer.</p><pre>var sheetDestination: SheetDestination = .none {<br>    didSet {<br>        showSheet = true<br>    }<br>}</pre><p>Every time the <em>sheetDestination</em> is being set, we set <em>showModal</em> to true.</p><pre>VStack {<br>    Button(&quot;Show Settings&quot;) {<br>        self.sheetNavigator.sheetDestination = .settings<br>    }<br>    Button(&quot;Show Profile&quot;) {<br>        self.sheetNavigator.sheetDestination = .profile<br>    }<br>}.sheet(isPresented: self.$sheetNavigator.showSheet) {<br>    self.sheetNavigator.sheetView()<br>}</pre><p><strong>What‘s next?</strong></p><p>In using our navigator, we managed to condense our view and moved most of our navigation logic out of it. But there is still room for improvement. We can take advantage of the fact that Swift enums support associated values and pass additional data to the presented sheet views.</p><p>For instance, we can make the profile enum case accept a String as parameter, if we want to pass the name of the user to the profile view.</p><pre>enum SheetDestination {<br>    case none<br>    case settings<br>    case profile(name: String)<br>}</pre><p>When setting the <em>sheetDestination</em> to the <em>profile</em> case, our call site would look like this.</p><pre>Button(&quot;Show Profile&quot;) {<br>   self.sheetNavigator.sheetDestination = .profile(name: &quot;Christoph&quot;)<br>}</pre><p>The profile case of the switch statement within the <em>sheetView</em> function, has to be adjusted as well. Here, we can use the given parameter and pass it to the ProfileView.</p><pre>case .profile(name: let userName):<br>         return ProfileView(name: userName).eraseToAnyView()</pre><p>Keep in mind to avoid too many destinations in one Navigator class. In fact, each view you are using should have its own Navigator.</p><p>To establish a consistent style, you could use a Navigator Protocol each Navigator can confirm to.</p><pre>protocol NavigatorProtocol: ObservableObject {<br>    associatedtype SheetDestination<br>    func sheetView() -&gt; AnyView<br>}</pre><p>I hope you enjoyed this little concept of handling multiple sheets. How do you handle navigating to different views in SwiftUI? Do you have similar approaches? Let us know! We‘d love to hear your ideas and hope this article helped to StepUp your developer game.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e9a73d99cd7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/stepup-development/handling-multiple-sheets-in-swiftui-2e9a73d99cd7">Handling multiple sheets in SwiftUI</a> was originally published in <a href="https://medium.com/stepup-development">StepUp Development</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>