<?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 Daniel Kuhlwein on Medium]]></title>
        <description><![CDATA[Stories by Daniel Kuhlwein on Medium]]></description>
        <link>https://medium.com/@danielkuhlwein_98584?source=rss-4b66459006bf------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*97QbCxcNh2XX9mhEl8d2Og.png</url>
            <title>Stories by Daniel Kuhlwein on Medium</title>
            <link>https://medium.com/@danielkuhlwein_98584?source=rss-4b66459006bf------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 21:17:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@danielkuhlwein_98584/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[Swift: Functions & Closures]]></title>
            <link>https://medium.com/@danielkuhlwein_98584/swift-functions-closures-b8bedad1c9cd?source=rss-4b66459006bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/b8bedad1c9cd</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Daniel Kuhlwein]]></dc:creator>
            <pubDate>Mon, 27 Mar 2017 17:02:23 GMT</pubDate>
            <atom:updated>2017-03-27T17:02:23.830Z</atom:updated>
            <content:encoded><![CDATA[<p>If you are new to Swift and functional programming in general (like me) understanding functions and closures can be confusing. This article aims to clear up any of that confusion.</p><p>Right off the bat, it’s important to understand some of the unique properties of functions and closures in Swift. If you’re familiar with Java (like me), then you might be thinking “Functions are just like methods!”, but you’d only be half right. In Swift, functions can actually be <em>assigned</em> to variables, and they can be passed in and out of other functions as arguments.</p><blockquote>ŎםŎ say what now? they CAN??</blockquote><p>If you’ve never heard of this before (like me) then I will allow you some time to clean your brains off the floor.</p><p>Back? Okay! In this way, functions in Swift are treated as “first-class objects”. Just like an Int or a String can be assigned to a variable, a function can also be assigned to a variable. Another important thing to understand about functions in Swift, is that they can “capture” variables that exist outside of their local scope. <em>More on this later…</em></p><p>Now, suppose you wanted to create one of these fancy functions. There’s actually two ways you could go about doing this, depending on the situation. Functions can be declared with the func keyword <strong>OR </strong>simply with { } which is known as a “closure expression”. <em>We’ll take a look at some examples later…</em></p><p>So, you might be asking yourself “What is the big deal of being able to treat functions like this? How does it benefit me?” As demonstration, consider an array in Swift. It has a map function that takes another function in as argument, and applies that function to every element in the array, returning a new array with the results. For example, an Integer doubler:</p><pre>// Here is a function that will double an int<br>func doubleInt(i: Int) -&gt; Int { return i * 2 }</pre><pre>// Now, declare an array and run the doubleInt function<br>let array = [1, 2, 3, 4];<br>array.map(doubleInt);</pre><pre>print(array);</pre><pre>// Output of print: [2, 4, 6, 8]</pre><p>There are a few other useful functions in array that also take functions as arguments.</p><ol><li>filter (Takes in a function that will test each element for inclusion in the resulting array)</li><li>sort (Takes in a function that will determine a custom ordering for two elements)</li><li>reduce (Takes in a function that will incorporate each element into a running value. For example, find the sum of all values, find the max/min, etc.)</li></ol><p>Now, prepare yourself for some deep, Inception level, recursion magic… You can set the return of a function to be not just any variable like Int or String, but another function itself! Let’s see an example:</p><pre>// Declare a function that returns another function<br>func returnFunc() -&gt; (Int) -&gt; () {<br>    func innerFunc(i: Int) {<br>        println(&quot;\(i) was passed to returnFunc&quot;)<br>    }<br>    return innerFunc<br>}</pre><pre>// Now let&#39;s assign the returnFunc to a variable before we call it<br>// Just because we can =P<br>let f = returnFunc</pre><pre>f(2) // This will print &quot;2 was passed to returnFunc&quot;</pre><p>Remember when we talked about closures? Let’s dive into that a bit more. So we know that it’s a way to declare a function and it uses this syntax { }. Remember our doubleInt function? We declared it using the closure syntax:</p><pre>func doubleInt(i: Int) -&gt; Int { return i * 2 }</pre><p>This is really nice, concise way of writing code. We don’t have to declare the function separately, taking up unnecessary lines of code. Just like we wouldn’t write:</p><pre>var sum = 1 + 1<br>someFunction(sum)</pre><p>When we could simply have it all in one line like:</p><pre>someFunction(1 + 1)</pre><p>In this way, closures let us write cleaner code. However, the rabbit hole only gets deeper from here. So, let’s take our doubleInt function from earlier:</p><pre>func doubleInt(i: Int) -&gt; Int { return i * 2 }</pre><p>We can actually write this statement like this instead:</p><pre>[1, 2, 3].map { $0 * 2 }</pre><blockquote>°Д° whoa buddy! hold the phone! how did we do that??</blockquote><p>Let me explain.</p><ol><li>Since all the types can be inferred by Swift, there’s no need to explicitly declare them. Giving us: [1, 2, 3].map( { i in return i * 2 } )</li><li>And since our closure expression is a single expression, Swift will infer that we want to return the value of the expression. Giving us: [1, 2, 3].map( { i in i * 2 } )</li><li>Swift (being the nice pal that it is) provides us shorthand notation for the arguments to a function ($0 for the first argument, $1 for the second, etc.) Giving us: [1, 2, 3].map( { $0 * 2 } )</li><li>When the last argument for a function is a closure expression, we’re allowed to move the expression outside of the parenthesis of the calling function. This comes more in handy when we have a multi-line expression, as it will be easier to read. Nevertheless, it gives us: [1, 2, 3].map() { $0 * 2 }</li><li>Finally, since our calling function actually has no arguments other than the closure expression, we don’t even need to include the parethesis. Giving us: [1, 2, 3].map { $0 * 2 }</li></ol><p>Neato! Hopefully this gives you a better understanding on functions and closures, and how to use them in Swift.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b8bedad1c9cd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Swift Playgrounds]]></title>
            <link>https://medium.com/@danielkuhlwein_98584/swift-playgrounds-5d260233c49f?source=rss-4b66459006bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/5d260233c49f</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Daniel Kuhlwein]]></dc:creator>
            <pubDate>Sun, 19 Mar 2017 19:24:44 GMT</pubDate>
            <atom:updated>2017-03-19T19:24:44.593Z</atom:updated>
            <content:encoded><![CDATA[<p>Being able to jump straight into code, without the hassle of creating and setting up a project, is simply game changing. Apple introduced Playrounds along with Swift in 2014, and since then people all over the world have been able to quickly start formulating their ideas in code at the touch of a single button.</p><blockquote>Playground — noun: a place where people can play</blockquote><p>To get started with your own playground, simply launch Xcode and select Playground from the splash screen. Or use the shortcut : (⌥ + ⇧ + ⌘ + N). It should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/932/1*nJpDb04Tvq9Fan89M3Io9A.png" /></figure><h3>How to play</h3><p>Basically, playgrounds let you interact with your code immediately. You can simply type up your code, and your playground will compile and run your code live, in the background!</p><p>Say for example you create a variable name, you can see it pop up in the sidebar in just a couple seconds:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4A9Rh2AyNTeNbMiw3wBdZA.png" /></figure><p>Now let’s try something a bit more interactive. Say we declare an array, and then iterate through the array.</p><pre>var array = [1, 2, 3, 4, 5]</pre><pre>for element in array<br>{<br>    element<br>}</pre><p>Since we are in a playground, we can see exactly what this code is doing in the form of a graph! How handy is that?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/452/1*UIbdx6fBA_BK3OlBFAHYDA.png" /></figure><p>But the fun doesn’t stop there! Oh boy, we’re just getting started &gt;:] There are actually an infinite number of ways to use Playgrounds to interact with your code. I was able to find one excellent example that really showcases what is possible within a Playground.</p><iframe src="https://cdn.embedly.com/widgets/media.html?url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D_JotNYSp0zc&amp;src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F_JotNYSp0zc&amp;type=text%2Fhtml&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/6c6c0ad33554219fe3f2ff10447d9231/href">https://medium.com/media/6c6c0ad33554219fe3f2ff10447d9231/href</a></iframe><blockquote><a href="https://github.com/MacMeDan/SpriteKitCollisions">Source code available here</a></blockquote><p>By showing the assistant editor, we can see the output this program is generating. We can see that it is using SpriteKit to create the blocks as well as the ball. By viewing it in real-time, we can make changes to the code and see how they affect the final result without having to rebuild the entire program.</p><h3>Summary</h3><p>Playgrounds are a place for to play. Apple brings Playgrounds to Xcode to provide developers a rich development experience, where people can feel free to create and experiment in a rewarding and interactive environment.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5d260233c49f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting Started With Xcode]]></title>
            <link>https://medium.com/@danielkuhlwein_98584/getting-started-with-xcode-11b37c73a64f?source=rss-4b66459006bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/11b37c73a64f</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[apple]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[beginner]]></category>
            <category><![CDATA[xcode]]></category>
            <dc:creator><![CDATA[Daniel Kuhlwein]]></dc:creator>
            <pubDate>Sun, 19 Feb 2017 02:03:54 GMT</pubDate>
            <atom:updated>2017-02-19T02:03:54.968Z</atom:updated>
            <content:encoded><![CDATA[<p>Xcode is an IDE (Integrated Development Environment) available on macOS. It provides powerful tools in an easy to use interface for developing great applications for all of Apple’s platforms. iOS, watchOS, tvOS, and macOS applications can all be easily developed with incredible support from Apple in the form of libraries and frameworks, making even game development simpler than you imagined.</p><p>Getting started in Xcode is easy. Simply launch the application from Launchpad, or by using Spotlight.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pKYd-2wVyXdAZbYC_Rj2ww.png" /></figure><p>When you launch Xcode, it will display the “Welcome to Xcode” screen, with options to open previous projects, or create something new.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o6Ljnop2wCbqXYQzemV1BA.png" /></figure><p>You can select “Get started with a playground” to quickly jump into coding and whip up an idea in a lightweight, versatile, and yet still very powerful environment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xehbzxzBahn9CgCXHUfPog.png" /></figure><p>The other option is to create a new Xcode project, so let’s jump into that. When you select this option, Xcode will ask you what type of Xcode project you want to create. There are several options ranging across Apple’s platforms. For this tutorial, we’re going to select a “Single View Application” because it is very simple.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WshloWhY-NHB3Dxumg8bTw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0qRi6lx9bDyjvHwqR13lOQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DdsfiCk3p8mwLMDpjeNm6Q.png" /></figure><p>Okay, so our project has been created and now we’re in the IDE. Let’s explore a bit of the UI first and get comfortable. We can break down the UI into 3 sections for now. In the left we have the navigation pane. We can use this pane to navigate our projcet’s files and class hierarchy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/1*O8oId6ByQNyhISEKdVX8Gg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/516/1*5PGeGZXay8klQaTouMTsCA.png" /></figure><p>In the middle is the content viewer. This window will display whatever file we currently have selected. For example, we currently have the entire Xcode project selected “XcodeTutorial”, so it displays a number of options/configurations for this entire project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R-RHwmgS-vJM3i-pQDXwXg.png" /></figure><p>If we selected one of the Swift files instead, for example if we select the ViewController, you can see that the content viewer now displays this file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*twdAYOr__DjIM_DEeQPIhg.png" /></figure><p>Next is the right pane, the utilities pane. This is a dynamic section that responds to whatever we have selected in the content pane. For example, with the ViewController swift file selected, the utilities pane looks like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/514/1*OFh6r7wXBRyhUNgaSJv5wQ.png" /></figure><p>And when we select a different file, say the Main.storyboard (our main view in this application), the utilities pane displays relevant utilities.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/514/1*QrgtCzKKB4WrOzS2rfu9-w.png" /></figure><p>So, what exactly is “Main.storyboard”? If you’re familiar with Java, you can think of this as Xcode’s GUI builder, kind of like SceneBuilder. Only this GUI builder is 100x more powerful, elegant, and easy to use! Right now you can see that it shows the main page of this single page application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2yjP7xaUHnCHnqPHAV7GyA.png" /></figure><p>Oh no! It’s blank! How can we add components to this UI view? Let me direct you over to the right pane again (the utilities pane). If you look near the bottom of this pane, you can see what is referred to as the object library. There is even a little search bar at the bottom to let us find exactly what we’re looking for.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/514/1*36_BXIgDc-AEcAwbQ54Ktw.png" /></figure><p>For example, if we type in the word button, we can quickly find the button component, and simply drag it somewhere into our UI view.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RYRc2NA6FmCfX_0bhp81UQ.png" /></figure><p>That’s great! But how can we get this button to perform some sort of action? This is where one of Xcode’s very cool features comes in to play, and it’s going to make this task very simple! We won’t need to edit the properties of this button to give it some sort of ID that we can reference from one of our Swift files. We can simply drag and drop it into any Swift file that we want to use it in, by holding control when dragging! How cool is that?</p><p>To allow this action, we need to change our view. In the top right, in the toolbar, we can select “Show Assistant Editor” (the button with two circles). This will allow us to select to files to view in the content view at the same time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/210/1*_BWUkvFVGDBvW_8WBuU8Bg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*V3h9OzDLArUxbDuAnk6f0A.gif" /></figure><p>We can either connect this UI component as anattribute, or by creating a function for it. In this case, I am creating a function called “buttonAction” that will be invoked when the user taps our button.</p><p>So, if I simply add a print statement to this method, I think we’re ready to start testing our application!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*wCRehEgOnu8o5lPNdLRoLA.png" /></figure><p>To start your application, use the start/stop button in the top left, in the toolbar.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*ZTAh71kamiMPLVz6z6Z-CQ.png" /></figure><p>Here we have the option of selecting what kind of device we want to run this application on. When creating this project, I chose to create an iPhone app, but you can choose to create an iPad app, or even a universal app! The iPhone 7 selection as you see here will run the app using the Simulator application. This application runs on your Mac and acts as if it were an iPhone or an iPad. You also have the option of plugging in your own device for testing via USB. Okay, let’s run our app!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*-gG0l8Jh3-ZThIWijo7yiw.png" /></figure><p>As you can see, it’s beautiful. Let’s ensure that our button action is working. If we go back to Xcode, you can see the 4th pane that has been automatically shown at the bottom. This is the debug pane that contains our output. When we tap the button, it should print “yo” into this output area.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AZAtJcTHtViXJ-w34n3S_Q.png" /></figure><p>Look at that! It works! Perfect.</p><p>To the right of the output area, you’ll notice the second part of the debug pane. This is the step-through section, which allows you to step through your application and hit various breakpoints within your code when testing and debugging.</p><p>Now that you know the basics of Xcode, let me teach you some more advanced tricks that Xcode has to offer. These will really come in handy when testing, debugging, and optimizing your application.</p><p>Going back to our navigator pane, you can see that it automatically changes to the debug view when running an application. This will show details on CPU, Memory, Disk Usage, etc. And you can even view processes by thread (as seen below the CPU, Memory, etc.)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/516/1*fyidrQplmvTVIqDvlBHFHQ.png" /></figure><p>When you click on one of these monitors. CPU, Memory, etc. It will show even more detail in the content pane. For example, if we select CPU:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DBLbum175gKpGkMcPEmiBw.png" /></figure><p>Each of these views provide rich visualization of data being collected on the performance of your application. This will allow you to easily optimize and debug your application. See below for each of the other views:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x9F27YJJvwhtVTAa7NESPA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zuqTBg8Q-TsvOp5-oLwZcQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C2H2pWxI0ic3OzMvdWkftA.png" /></figure><p>Lastly, I want to close with Xcode Preferences. There are many settings to configure within the preferences, but most notably, Xcode gives you full control of the look and feel of your editor, and allows for a full remap of shortcuts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HUeHMZld4uviID_U_cgYBw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*anadbJJYAyD4tUii6uO2Vg.png" /></figure><p>Happy Xcoding! (ﾉ◕ヮ◕)ﾉ*:・ﾟ✧</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=11b37c73a64f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Swift / Java]]></title>
            <link>https://medium.com/@danielkuhlwein_98584/swift-java-2e47fdbb9390?source=rss-4b66459006bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e47fdbb9390</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Daniel Kuhlwein]]></dc:creator>
            <pubDate>Tue, 17 Jan 2017 21:17:39 GMT</pubDate>
            <atom:updated>2017-01-17T21:17:39.461Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/298/1*OPx7Ux2q_S7FHGxI6AyvvQ.png" /></figure><p>Swift and Java may both be programming languages, however, they are still very different. This article aims to provide you with an understanding of how one differs from the other.</p><h3>Fundamental Differences</h3><h4>History</h4><p>Swift was developed 19 years after Java, and for an entirely different use case. Both languages have some similarities, but are fundamentally developed for different purposes.</p><p>Java was developed by Sun Microsystems, in a time when most programming languages were still very low-level. Java was aimed at revolutionizing the industry by providing a high-level language that would be compiled into Java byte code, for interpretation by the JVM. A JVM was made for each specific OS platform, which allowed Java code the unique ability of being able to be written once, and run anywhere.</p><p>Swift was developed by Apple, in 2014. It was made open-source in 2015 and though it is continuing its rapid growth, is still not able to fully replace its “successor” Objective-C. It was developed to be as modern as a programming language could be, with cues taken from various other programming languages after years of learned best-practices and approaches to software development. It has a special focus on being very expressive, so that understanding of what the code is doing can be easily understood simply by reading it. Security and speed also took front seat during development.</p><h4>Platform Availability</h4><p>Whereas Java is available across every OS and a JVM written for every OS (meaning that Java code can be compiled and ran anywhere), Swift is only available on Apple’s platforms, and can only be written with on MacOS using Xcode. Though, there are talks of bring Swift to Linux as well, now that it is open source. Applications developed using Swift are also limited to Apple’s platforms, MacOS, iOS, WatchOS, and tvOS.</p><h3>Syntax/Functionality</h3><p>Now, lets go over some of the syntactic and functional differences between the two languages.</p><h4>Semicolons</h4><p>In <strong>Java</strong>, statements must be closed with a semicolon.</p><pre>int sum = 1 + 1;</pre><p>In <strong>Swift</strong>, no semicolon is required, but you can still include them if you want.</p><pre>var sum = 1 + 1</pre><h4>Type Inference</h4><p>In <strong>Java</strong>, types must be explicitly declared.</p><pre>final String myName = “Daniel”</pre><p>In <strong>Swift</strong>, as long as the variable declaration and assignment both happen on the same line, types will be inferred.</p><pre>let name = &quot;Daniel&quot;</pre><p>In <strong>Swift</strong> it’s still possible to explicitly declare types, and in the case of separated declaration and assignment statements, it is <em>required</em>.</p><pre>let name: String = &quot;Daniel&quot;</pre><pre>let name: String<br>name = &quot;Daniel&quot;</pre><h4>Constants:</h4><p>In <strong>Java</strong>, constants are declared using the keyword <em>final</em>.</p><pre>final String name = &quot;Daniel&quot;;</pre><p>In <strong>Swift</strong>, constants are declared using the keyword <em>let</em>.</p><h4>Emoji:</h4><p>In <strong>Java</strong>, it is not possible to use emoji.</p><pre>String 🌮 = &quot;taco&quot;; //ERROR</pre><p>In <strong>Swift</strong>, Unicode characters are recognized, and emojis can be used.</p><pre>var 🌮 = &quot;taco&quot;</pre><h4>Swift Specific: Tuples</h4><p>In <strong>Swift</strong>, there is a special data type known as a Tuple. A tuple is a variable that is composed of 2 or more values. These can be very useful, but have specific use cases, and times that require more than 2 or 3 values may be better represented using an array anyway.</p><pre>var rgb = (25, 50, 75)</pre><p>Values are then retrieved using the following syntax:</p><pre>rgb.0<br>rgb.1<br>rgb.2</pre><p>Values can also be retrieved in a more explicit manner if the Tuple is declared more explicitly:</p><pre>var rgb = (Red: 25, Blue: 50, Green: 75)</pre><pre>rgb.Red<br>rgb.Blue<br>rgb.Green</pre><p>In <strong>Java</strong>, the closest equivalent to a Tuple is simply an array.</p><pre>int[] rgb = {1,2,3};</pre><h4>Swift Specific: Multiple Return Values</h4><p>In <strong>Swift,</strong> tuples make it possible to create a function with multiple return values. Simply create a function that returns a tuple!</p><pre>fun minMax(array: [Int]) -&gt; (min: Int, max: Int)<br>{<br>    var currentMin = array[0]<br>    var currentMax = array[0]<br>    for value in array[1..&lt;array.count]<br>    {<br>        if value &lt; currentMin<br>        {<br>            currentMin = value<br>        } <br>        else if value &gt; currentMax<br>        {<br>            currentMax = value<br>        }<br>    }<br>    return (currentMin, currentMax)<br>}</pre><p>The <strong>Java</strong> equivalent to doing this would be to just return an array.</p><pre>private int[] findMinMax(int[] array)<br>{<br>    int currentMin = array[0];<br>    int currentMax = array[0];<br>    for(int value : array)<br>    {<br>        if(value &lt; currentMin)<br>        {<br>            currentMin = value;<br>        } <br>        else if(value &gt; currentMax)<br>        {<br>            currentMax = value;<br>        }<br>    }<br>    int[] minMax = {currentMin, currentMax};<br>    return minMax;<br>}</pre><h4>Swift Specific: Optionals</h4><p><strong>Swift</strong> offers another unique data type called <em>optionals</em>. These data types allow special handling in the event a value is <em>nil</em> (null). For example, we can use the following code to print out a greeting with someone’s nickname if they provided one, or else just use their full name.</p><pre>let nickName: String? = nil</pre><pre>let fullName: String = &quot;Daniel Kuhlwein&quot;</pre><pre>let informalGreeting = &quot;Hi \(nickName ?? fullName)&quot;</pre><p>Since nickName was set to nil, informalGreeting is set to “Hi Daniel Kuhlwein”</p><p>In Java, the only equivalent way to do this that I can think of is the following:</p><pre>String nickName = null;</pre><pre>String fullName = &quot;Daniel Kuhlwein&quot;;</pre><pre>String informalGreeting = &quot;Hi &quot; + ((nickName != null) ? nickName : fullName);</pre><h3>Getting Started</h3><h4>In Java</h4><p>In order to get up and running in <strong>Java</strong>, the simplest way to do is is via the command line. First, create a .java file using a text editor, then compile this source code and run it.</p><pre>javac HellowWorld.java<br>java HelloWorld</pre><h4>In Swift</h4><p><strong>Swift</strong> can also be run from within the command line, but perhaps the simplest and most effective way to get started in Swift, is via <em>Playgrounds</em>. Simply open Xcode, and create a new Playground. It will look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jBfieVVHTHh33-qoVgB9KA.png" /><figcaption>A Swift Playground</figcaption></figure><p>Swift Playgrounds are compiled on the fly, with code output along the right column. Playgrounds also have visualization tools, as you can see in this example with the sine graph. These tools make Playgrounds both very powerful and very useful wen playing with Swift code.</p><h3>Conclusion</h3><p>While Swift is still very new, proprietary, and still very much a trend, it’s easy to see how powerful it is and how many useful applications there are for it. While it may not revolutionize the industry as Java once had, it is still a strong programming language in its own right, and may well continue to overtake Objective-C completely, at least for development of software for Apple’s systems.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e47fdbb9390" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>