<?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 Sarin Swift on Medium]]></title>
        <description><![CDATA[Stories by Sarin Swift on Medium]]></description>
        <link>https://medium.com/@sarinyaswift?source=rss-ed60eee1cd58------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*6584npzoLEUFRVWF3p_DVQ@2x.jpeg</url>
            <title>Stories by Sarin Swift on Medium</title>
            <link>https://medium.com/@sarinyaswift?source=rss-ed60eee1cd58------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 13 Jul 2026 10:18:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sarinyaswift/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[PanGesture Slidable View — Swift 5]]></title>
            <link>https://medium.com/@sarinyaswift/pangesture-slidable-view-swift-5-6718517f94a8?source=rss-ed60eee1cd58------2</link>
            <guid isPermaLink="false">https://medium.com/p/6718517f94a8</guid>
            <category><![CDATA[swift-programming]]></category>
            <category><![CDATA[uikit]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Sarin Swift]]></dc:creator>
            <pubDate>Wed, 24 Jun 2020 01:17:13 GMT</pubDate>
            <atom:updated>2020-07-03T16:10:39.420Z</atom:updated>
            <content:encoded><![CDATA[<h3>PanGesture Slidable View — Swift 5</h3><h4>Using custom PresentationController and PanGestureRecognizers</h4><p>Having recently spent countless hours of searching for tutorials that simply explain how to create a “draggable” view, I’ve decided to take a stab at creating a tutorial that I wish I had when l first started out. <br>In this article, I’m going to show you step by step how we can achieve this beautiful draggable popup view in Swift!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FXE1PSUsMQVtEOtgzfX%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FXE1PSUsMQVtEOtgzfX%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FXE1PSUsMQVtEOtgzfX%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="773" frameborder="0" scrolling="no"><a href="https://medium.com/media/345278cad11a97756e086b3b25b9a2ff/href">https://medium.com/media/345278cad11a97756e086b3b25b9a2ff/href</a></iframe><p>The main frameworks we’re going to be using from UIKit in this tutorial are: <a href="https://developer.apple.com/documentation/uikit/uipresentationcontroller">UIPresentationController</a>, and <a href="https://developer.apple.com/documentation/uikit/uipangesturerecognizer">UIPanGestureRecognizer</a>.</p><blockquote>A UIPresentationController is an NSObject that manages the transition animations and the presentation of view controllers onscreen.</blockquote><blockquote>A UIPanGestureRecognizer is a distinct gesture recognizer that interprets panning gestures. — Apple Docs</blockquote><h3>Step 1: Create your custom UIPresentationController</h3><p>In an Xcode project, go ahead and create a new Swift file called <strong>FilterPresentationController.swift<br></strong>This class will conform to UIPresentationController where we’ll be overriding methods and adding customization.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9808f84ef8dab98796a592a9de4d2e8b/href">https://medium.com/media/9808f84ef8dab98796a592a9de4d2e8b/href</a></iframe><p>Let’s not get overwhelmed by this chunk of code. We’re going to go through it step by step.</p><ol><li>This method initializes our class to handle the transitioning between two view controllers and sets a blur effect on the containerView (The view that is currently behind the presented view). <br>You also see here that we’re adding a tapGesture so that we can dismiss the presentedViewController!</li><li>This function lets you customize the point at which you want the view to show. We set the presented view controllers starting point (`x = 0`) to the top left of the screen, the height (`y = 0.4%`) to be a fraction of the screen. In addition, the width is equal to the container view (`width = screen width`) and the height to be a fraction of the screen (`height = 0.6%`). You can customize the size to however you’d like! Very cool to see the views change as you tweak the numbers.</li><li>Adding the blurEffectView on the background as it starts the presentation.</li><li>Removes the blurEffectView on the background as it dismisses.</li><li>Here is where we can round our presentedViewController.view’s corners! I’m using a helper method for rounding which will be covered in Step 2.</li><li>The layout has ended on the container view.</li><li>The selector method for when the tapGesture fires off an action. Where we dismiss the presentedViewController.</li></ol><h3>Step 2: Adding a helper method to round the view’s top left and right corners</h3><p>Since the presentedViewController’s height is only 0.6 % of the entire screen. That means if we set <em>presentedView?.layer.cornerRadius = 22</em>, the bottom corners will round as well. Like in this picture below.. which we’re not going for here!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/406/1*iXXS63gD1jXD09s20JRF-g.png" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2fce328bb47eb14cf38743301a13252d/href">https://medium.com/media/2fce328bb47eb14cf38743301a13252d/href</a></iframe><p>roundCorners(_:radius:) method allows you to specify which corners you’d want with a cornerRadius such as: topLeft, topRight, bottomLeft, bottomRight, and allCorners. Now that we call this helper method on .topLeft and .topRight, it’s back to looking normal!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/398/1*0kw8ENy7P4uzGseqF-WTBg.png" /></figure><h3>Step 3: Creating the main view controller</h3><p>If you already have a view controller in mind that you’d want to present the presentation view controller on, great. If not, you can create a simple view controller with a button like below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/396/1*KXeFMmfZsp4SOwb5kjiDHg.png" /></figure><h3>Step 4: Creating the presented view controller</h3><p>This is going to be the filter view controller that’s presented by our main view controller above.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/398/1*0kw8ENy7P4uzGseqF-WTBg.png" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/51bdd50eb299da402d125da864e536ca/href">https://medium.com/media/51bdd50eb299da402d125da864e536ca/href</a></iframe><p>Code above sets up a viewController with a topView, which you might have guessed already why we would add an empty view with a clear background.. Correct! We’re going to be adding a panGestureRecognizer to that so we can drag the view!</p><h3>Step 5: Implement our custom presentation</h3><p>Let’s go back to the main view controller you created and add in some code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/45c63bcb7ac245c0c6b1d84c6cea20bb/href">https://medium.com/media/45c63bcb7ac245c0c6b1d84c6cea20bb/href</a></iframe><ol><li>We’re going to present our FilterViewController using a custom modalPresentationStyle as well as setting the transitioning delegate to self(ViewController).</li><li>Here is where we declare our custom UIPresentationController that we created in step 1. We know that the FilterViewController will present itself only 0.6 % height of the whole screen like in the picture below👇🏼👇🏼</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/398/1*0kw8ENy7P4uzGseqF-WTBg.png" /></figure><h3>Step 6: Add a PanGestureRecognizer to FilterViewController</h3><p>We’re so close to finishing with this entire implementation! A panGestureRecognizer is a subclass of the UIGestureRecognizer class that looks for panning or dragging gestures. Perfect use in this case for dragging a view down. Let’s add this gesture to the FilterViewController’s topView.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9c5c681d00d408ad2d560e9c754538cc/href">https://medium.com/media/9c5c681d00d408ad2d560e9c754538cc/href</a></iframe><p>Above you see that we added 2 new properties to the FilterViewController: pointOrigin which is a CGPoint along with hasSetPointOrigin.</p><ol><li>We should set the point origin (pointOrigin) during the first call to viewDidLayoutSubviews. We put a check around this since any time the view changes its points, it will call viewDidLayoutSubviews.</li><li>Adding the panGesture to topView with an action so whenever it receives a pan or drag, it will trigger an action!</li><li>Here’s where the math comes in.. we first get the coordinates of the pan gesture, where that’s happening in the view. I’m putting a guard statement here because I don’t want to move the view up if the pan gesture moves upward (which means it increases negatively). <br>On line 28, we’re setting the FilterViewController’s frames to the current point origin with the addition of how far the pan gesture went in the y direction. For example when the user drags straight down, this effects the y position.<br>The last step is to calculate the velocity of how fast the gesture was. This is super cool because you can simply call sender.velocity(in: view) and that’ll give you a CGPoint object. We can check against the velocity’s y position. And here I’m allowing the velocity of 1300 or more to dismiss the view controller. (The greater the number, means the faster the user dragged on the screen). If the velocity isn’t too fast, I’m resetting the view back to it’s original point.</li></ol><p>That was quite a lot to comprehend. But let’s see a little demo below what that math looks like in action.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FXE1PSUsMQVtEOtgzfX%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FXE1PSUsMQVtEOtgzfX%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FXE1PSUsMQVtEOtgzfX%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="773" frameborder="0" scrolling="no"><a href="https://medium.com/media/345278cad11a97756e086b3b25b9a2ff/href">https://medium.com/media/345278cad11a97756e086b3b25b9a2ff/href</a></iframe><h4>Wrapping Up</h4><p>And that’s a wrap on today’s tutorial on custom presentation transitions along with the great use of pan gesture recognizers. To give you more context, here are a couple examples of apps that have a similar feature to what we covered in this tutorial: Yelp, DoorDash, Instagram, OpenTable, etc. <br>I know it’s 2020 and SwiftUI has been out for a while now, but hopefully there’re some people out there that needed this guide! And I hope in the next tutorial, I can start diving into SwiftUI and creating articles about that! Stay tuned and please give me a follow if you’d want to see more of these :)</p><p><strong>Resources:</strong><br><a href="https://www.raywenderlich.com/3636807-uipresentationcontroller-tutorial-getting-started">UIPresentationController</a> — raywenderlich<br><a href="https://medium.com/@vialyx/import-uikit-custom-modal-transitioning-with-swift-6f320de70f55">Custom modal presentation </a>— Maxim Vialyx<br><a href="https://www.youtube.com/watch?v=acPVLXQshYk">Draggable View</a> — YouTube/Wilson Balderrama<br><a href="https://stackoverflow.com/users/2525948/st%c3%a9phane-de-luca">Stéphane de Luca</a> — UIView extension</p><blockquote>Thank you for checking out this blog post!</blockquote><blockquote>If you have any questions or comments, please feel free to reach out to me. And don’t forget to give this article some claps! 👏🏼*up to 50x*👏🏼 if you found it helpful.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6718517f94a8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Heaps and Stacks Data Structure in Swift]]></title>
            <link>https://medium.com/@sarinyaswift/heaps-and-stacks-data-structure-in-swift-9c908926528b?source=rss-ed60eee1cd58------2</link>
            <guid isPermaLink="false">https://medium.com/p/9c908926528b</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[data-structures]]></category>
            <dc:creator><![CDATA[Sarin Swift]]></dc:creator>
            <pubDate>Sat, 07 Dec 2019 20:09:42 GMT</pubDate>
            <atom:updated>2019-12-07T20:09:42.290Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VLHi-4CdxtoKZEkPPBYKUQ.jpeg" /><figcaption><a href="https://unsplash.com/@markusspiske">Markus Spiske</a> on Unsplash</figcaption></figure><p>This article is an extension from my recent article: <a href="https://heartbeat.fritz.ai/memory-management-in-swift-heaps-stacks-baa755abe16a"><strong>Memory Management with Heaps &amp; Stacks</strong></a>. I wanted to touch more based on the data structure of heaps and stacks since Swift used these terms to manage memory. If you want to learn more on swift’s memory management and haven’t yet checked out that article, I highly recommend checking it out!🔝🔝</p><p>Today’s article is going to go in detail of <strong>what</strong> these data structures are and <strong>how</strong> you would implement it in Swift!</p><h3>Heaps</h3><blockquote>“Not all roots are buried down in the ground some are at the top of the tree.” ― Jinvirle</blockquote><p>The heap data structure allows us to find minimum and maximum values which is laid out very similarly to the tree data structure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vny4V_W_4o_bjqdDVbL1Sw.png" /></figure><p>In the diagram above, we can see that the data represents nodes which has a value, a left reference, and a right reference. There can be 2 types of heaps: min heaps &amp; max heaps.</p><p><strong><em>Min heaps — </em></strong>The parent node’s value must always have a <em>smaller</em> value than that of both their child nodes. As seen in the diagram above, it can be referred that the smallest value will always be at the top. Min-heaps are often used to implement <a href="https://cocoapods.org/pods/PriorityQueue"><em>priority queues</em></a><em> </em>where it allows for efficient sorting of objects.</p><p><strong><em>Max heap — </em></strong>The parent node’s value must always have a <em>larger</em> value than that of both their child nodes.</p><p>Generally, heaps are implemented with an <strong>array</strong> under the hood. (Read more on arrays in <a href="https://heartbeat.fritz.ai/diving-into-data-structures-in-swift-arrays-4ffd516bde9b">this</a> article). We can say that each node in the heap matches an element of the array. This is so we can use indexing to point to our data within the tree. Let’s go ahead and write out the heap struct.</p><pre>struct MinHeap&lt;T: Comparable&gt; {<br>  var items = [T]() <br>}</pre><p>MinHeap conforms to the <strong>Comparable</strong> <strong>protocol</strong> which means that you can compare instances of the type with any of the relational operators, such as &gt;, &lt;, &gt;=, &lt;=,including ==.</p><p>We’re using generics once again! If you aren’t familiar with <strong>generics</strong> in Swift, they simply enable your models to be reusable and work with any given type. So when we initialize a MinHeap structure, we would initialize it as we would like <em>minHeap = MinHeap() </em>but instead we will explicitly give it a type:</p><pre>var minHeap = MinHeap&lt;Int&gt;()</pre><p>And this is how generics in Swift are so powerful and advantageous when creating or dealing with our own structures/classes, where we might want to use it on different data types!</p><p>Let’s go ahead and start implementing the fun part and give our <em>MinHeap</em> structure some functionality. 🔮🎱🔮</p><p><strong>Methods<br></strong>We are going to use the following heap, <em>diagram A</em>, to get an easier grasp on the different method implementations.</p><p>Can you guess what type of heap this is?…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m1hiu4YL442eCsNiYfBI5w.png" /><figcaption>Diagram A</figcaption></figure><blockquote>The array which represents this heap: <strong>[4, 7, 11, 9, 18, 15, 22]</strong></blockquote><p>You’re right! this is a min heap since the <em>smallest value</em> corresponds to our <em>root node</em>.</p><p><strong>Methods for index accessing:</strong></p><p><strong>getLeftChildIndex() </strong><em>Calculates our left child’s index when given a parent node’s index</em></p><pre>private func getLeftChildIndex(n: Int) -&gt; Int {<br>  return (2*n) + 1<br>}</pre><p>If we call this function giving the parameter <strong>0</strong>(node with value of 4), the function will return <strong>1</strong>(node with value of 7).</p><p><strong>getRightChildIndex() </strong><em>Calculates our right child’s index when given a parent node’s index</em></p><pre>private func getRightChildIndex(n: Int) -&gt; Int {<br>  return (2*n) + 2<br>}</pre><p>If we call this function giving the parameter <strong>1</strong>(node with value of 7), the function will return <strong>4</strong>(node with value of 18).</p><p><strong>getParentIndex() </strong><em>Calculates our parent’s index when given a child node’s index</em></p><pre>private func getParentIndex(n: Int) -&gt; Int {<br>  return (n - 1) / 2<br>}</pre><p>If we call this function giving the parameter <strong>1</strong>(node with value of 7), the function will return <strong>0</strong>(node with value of 4).</p><p><strong>Methods for checking states:</strong></p><p><strong>hasLeftChild() </strong><em>Returns a bool if the node’s given index has a left child</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d4f3c0498e6d082609d0957d6e87c3ac/href">https://medium.com/media/d4f3c0498e6d082609d0957d6e87c3ac/href</a></iframe><p>This may look confusing at first, but the logic is pretty straight forward! <br>1. In the first line of our function, we’re creating a variable that calculates what our “supposed” left child index would be. <br>2. The function will return <em>true</em> if <em>leftChildAtIndex</em> is less than the numbers of items in our heap structure.</p><p>Since the heap adds items from left to right, a node will only have a left child if the index is less than total amounts of elements in the array.<br>Let’s take an example from the diagram above. We want to check if the node with value of <strong>9</strong> has a left child or not. We want this to return <em>false</em> since we know from the image that it does not have a pointer to a left node. When we run the function the variable <em>leftChildAtIndex </em>will equal to<em> </em>7. And our total count of items in the heap is equal to 7. <em>leftChildAtIndex </em>isn’t less than 7 so it would return <em>false</em> as we expected!</p><p><strong>hasRightChild() </strong><em>Returns a bool if the node’s given index has a right child</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/228a8489dbbf023f96d0a67ce833987d/href">https://medium.com/media/228a8489dbbf023f96d0a67ce833987d/href</a></iframe><p>Has the same steps as the method above but instead we’re using the private function getRightChildAtIndex instead.<br>1. Calculate what our “supposed” right child index would be.<br>2. The function will return <em>true</em> if <em>rightChildAtIndex</em> is less than the numbers of items in our heap structure.</p><p><strong>Methods that return values in the heap:</strong></p><p><strong>leftChild()</strong> <em>Returns the left node’s value of a given node’s index</em></p><p><strong>rightChild()</strong> <em>Returns the right node’s value of a given node’s index</em></p><p><strong>parent()</strong> <em>Returns the parent node’s value of a given node’s index</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7fd5ae2ef28552ab27e1a3dab2e4cc02/href">https://medium.com/media/7fd5ae2ef28552ab27e1a3dab2e4cc02/href</a></iframe><p><strong>peek() </strong><em>Returns the value at top most of the heap</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1d64dcb2f92ac3b2d98563ab722e7fb1/href">https://medium.com/media/1d64dcb2f92ac3b2d98563ab722e7fb1/href</a></iframe><p>We make sure that our heap has a value within it so we can return the top most node(root node). If the heap is empty, we return <em>nil</em>.</p><p><strong>Method to build the heap:</strong></p><p>Before we go into the code, we will be using the <em>mutating</em> keyword to declare our function. Since structs are<em> value types</em>, by default, we can not modify the properties within its instance methods. The <strong><em>mutating</em></strong> keyword, in quick and simple terms, allows you to change(mutate) variables in place and these changes are written back to the original struct once the method ends executing.</p><p><strong>add() </strong><em>Inserts an element to the bottom of heap</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3cfd04873e8327036a6ee9b40c8b2c5e/href">https://medium.com/media/3cfd04873e8327036a6ee9b40c8b2c5e/href</a></iframe><ol><li>Add a new value to the end of our array. This is a min heap so we would need to make sure that the newly inserted value is greater than it’s parent’s value.</li><li>Create a variable to keep track of the index of the item we just added to the array. Declare it with a <em>var</em> keyword, hence the changing of value in our while loop.</li><li>Only begin to loop through this while loop if the parent node’s value is greater than the item we just added. Since this is a min heap and we <strong>need the parents value to be less than the child value!</strong></li><li>This built in <em>swapAt()</em> method on an array swaps the places of two items at their indices. This will swap the parent’s node to to take place of it’s child node.</li><li>Set the variable to be the parent index since now our parent index is the item we just added into the heap</li></ol><h3>Stacks</h3><p>Is a simple data structure where you can push(add items) onto the stack or pop to remove the top most element in the stack. <br><strong>FILO</strong>(First In Last Out)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0u9GjY2hQ8WLVzLNh2VJ_Q.png" /></figure><p>Let’s go ahead and look further into these method calls on the stack struct. But before implementing these methods, let’s create the base code for it.</p><pre>struct Stack&lt;T&gt; {<br>   var array = [T]()<br>}</pre><p>We create our Stack by using a <strong><em>struct</em></strong><em> </em>not a <em>class</em> because we want to be able to copy over the instantiated object in memory instead of having a reference point to it. Furthermore, we’re using <strong><em>generics</em></strong> so implementation on this stack can be on any type such as strings, integers, models, or objects.<br>On the second line, you can see that we are using an array to handle our stack and we declare it using ‘<em>var</em>’ since we will be adding and removing items!</p><p>Stacks can be implemented with any data structure of your choice. <br>In this tutorial I will be using an array, but as a stretch challenge, I encourage you to try using it on a <a href="https://medium.com/@sarinyaswift/linked-list-implementation-in-swift-4-caea34cbdada">linked list</a>!😁</p><p><strong>Methods in stacks</strong></p><p><strong>push() </strong><em>Adding something on to the stack.</em> <br>Runtime: O(1)<br>The first item can either be added to the front or the end of our data structure we chose to build with.</p><pre>mutating func push(_ item: T) {<br>   stack.append(item)          <br>}</pre><p>Because value types in Swift don’t allow us to modify properties within it, we have to use the mutating<em> </em>keyword<em> — </em><strong><em>mutating</em></strong><em> </em>allows us to modify(mutate😲😌) properties within the struct and update it.</p><p>The peek element is at the end of the array so we can make changes to the array generally with the runtime of O(1).</p><p><strong>pop() </strong><em>Deleting something off of stack and returning it’s value. </em><br>Runtime: O(1)<strong><br></strong>If we pushed from the end of the stack, we’ll have to remove it from the end as well. Same goes to the other way round.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/45494d89bd2372449c88a08f703a0395/href">https://medium.com/media/45494d89bd2372449c88a08f703a0395/href</a></iframe><ol><li>Making sure there’s something in the array so we can remove and return the last value.</li></ol><p><strong>top </strong><em>Checking the top most element without removing or changing the value.<br></em>Runtime: O(1)</p><pre>var top: T? {<br>   return stack.last<br>}</pre><p>You can see that <em>top</em> is not a method but a <strong><em>variable</em></strong> where we set it to the last element. Since this is an optional, it can return nil. Keep in mind here that Swift’s method <em>last</em> on an array will return nil if the collection we’re calling it on is empty.</p><p>Good reads to check💯:<br><a href="https://useyourloaf.com/blog/swift-equatable-and-comparable/">Swift Equatable and Comparable </a>— useyourloaf.com<br><a href="https://github.com/raywenderlich/swift-algorithm-club/tree/master/Heap">Heaps</a> — RayWenderlich</p><p>Video to check:<br><a href="https://www.youtube.com/watch?v=jHEUpfmMMt4">Heaps</a> — Devslopes</p><blockquote>Thank you for checking out this blog post!</blockquote><blockquote>If you have any questions or comments, please feel free to reach out to me. And don’t forget to give this article some claps! 👏🏼*up to 50x*👏🏼 if you found it helpful.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9c908926528b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Intro To The Graph Data Structure]]></title>
            <link>https://medium.com/@sarinyaswift/intro-to-the-graph-data-structure-a8277c6a2ad9?source=rss-ed60eee1cd58------2</link>
            <guid isPermaLink="false">https://medium.com/p/a8277c6a2ad9</guid>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[technical-interview]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[graph]]></category>
            <dc:creator><![CDATA[Sarin Swift]]></dc:creator>
            <pubDate>Sat, 17 Aug 2019 16:52:40 GMT</pubDate>
            <atom:updated>2019-08-17T16:52:40.798Z</atom:updated>
            <content:encoded><![CDATA[<h4>A real world problem solved through graph algorithms</h4><p>In todays article, we’ll take a dive in to learning more about graphs and their implementation to solving real world problems. Some common examples of situations where you can use graphs are: <em>social network(friends of friends)</em>, <em>page recommendations(based on most popular search)</em>, <em>the study of molecules in chemistry and physics</em>, <em>transportation networks</em>, and etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YwKEBBl-tnbxRM6J5E2UDQ.png" /></figure><h4>Things to know about graphs</h4><p><strong>Parts of a graph</strong><br>1. <em>Vertices</em>(nodes) — Where data is stored.<br>2. <em>Edges</em>(connections) — Connects 2 different vertices together. And they can also go in one direction. Which creates what’s called directed graphs or digraphs. Additionally, these edges can have weights.</p><p><strong>Types of graphs</strong><br>1. <em>Undirected</em> — Vertices on both sides of the edges have connection to each other and you can see that the relationship goes both ways.<br>2. <em>Directed</em> — Vertices on both sides of the edges have connection to each other. But the connection only goes one way(either from the first vertex to the second vertex, or otherwise).<br>3. <em>Weighted</em> — Branches that have a numerical weight.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IBtDZq0_4yWpXt0mhda0jw.png" /></figure><p><strong>Properties of a graph</strong><br>These properties define the graph itself, and is not a specific drawing of the graph. Here are some examples of graph properties.<br>1. <em>Path</em> — A sequence of vertices where they are adjacent to the vertex next to it<br>2. <em>Coloring</em> — An assignment of different colors to all vertices so the vertex at the end of each edge has a unique color<br>3. <em>Degree</em> — The number of edges that point out of the vertex<br>4. <em>Weight</em> — The value attached on its edges.<br>5. <em>Diameter</em> — The longest shortest path of that graph<br>6. <em>Connected graph </em>— When a graph has at least 1 vertex and there is a path between all vertices</p><p><strong>Problems that can be solved<br></strong>Here are a set of problems that can be questioned and solved in a graph model<br>1.<em>Verification</em> — Do these vertices form a path?<br>2. <em>Existence</em> — Is there a path in this graph?, Is there a path of length n?<br>3. <em>Instance</em> — Find a path from source vertex to distance vertex.<br>4. <em>Enumeration</em> — How many paths of length n exists in this graph?<br>5. <em>Optimization</em> — What is the longest path?, What is the shortest path?</p><p>Before heading in to solving a real world problem using graphs, I want to introduce algorithms that are very common and you will most likely be using or even get asked in some technical interviews.</p><h4>Graph Algorithms</h4><p><strong>Breadth First Search (BFS)<br></strong>BFS is a way to traverse through the graph in an order where it’s closest to the root vertex. In an iterative approach, we use a <a href="https://www.journaldev.com/21355/swift-queue-data-structure">Queue</a> data structure to keep track of each step in the traversals.</p><p>Below is a representation of running bfs on a graph. The list of order call orders from the first vertex visited, to the last vertex visited.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GyovphzwH4uRB5m5_VGduQ.png" /></figure><p><strong><em>Graph problems that can be solved using the BFS algorithm:</em></strong><em> </em><br>• Finding a path from a vertex to another<br>• Finding the minimum path from a vertex to another<br>• Finding all the paths from a vertex to another<br>• Finding a minimum spanning tree of an unweighted graph</p><p><strong>Depth First Search (DFS)<br></strong>DFS is a way to traverse through the graph in a way where it tries to go farthest from the root vertex. DFS requires to use a <a href="https://www.journaldev.com/21287/swift-stack-implementation">Stack</a> data structure so we go furthest away from the vertex instead of a level search like the bfs algorithm.</p><p>Below is a representation of running dfs on a graph. The list of order call orders from the first vertex visited, to the last vertex visited.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yemKC4m0jpNKj4WUCfAV4Q.png" /></figure><p><strong><em>Graph problems that can be solved using the DFS algorithm:</em></strong> <br>• Proving that a graph is connected<br>• Finding if there are existing paths within the graph<br>• Checking if a graph is bipartite (A graph is bipartite when the vertices can be divided into 2 independent sets and all the edges from one of the set connect to the other. Or we can also say a bipartite graph will not contain any odd length cycles.)</p><p><strong>Prim’s Algorithm<br></strong>Prim’s algorithm is a greedy algorithm that finds a minimum spanning tree in a weighted undirected graph. The algorithm builds up a tree one vertex at a time choosing its minimal weight of a vertex in each step.</p><p><strong>Dijkstra’s Algorithm<br></strong>Dijkstra’s algorithm is another greedy algorithm that that finds the shortest path between vertices in a graph. The algorithm finds the shortest path between the given vertex and every other connecting vertex to it. We can also optimize the run time of this algorithm by using a priority queue. This reduces the time of looking up the vertex that has the least distance.</p><h4>Sample Real World Implementation</h4><p>We’re going to examine graph theory application on <strong>Apple Map Routes</strong>. Have you ever noticed that out of thousands of routes you can take from getting from one location to another, Apple maps, or any other online map, will chose to take the shortest path.<br>However, The map applications we use have much more values to account for apart from its distance, such as traffic, or road blockage during specific times in a day.</p><p><strong>We are going to solve these common problems in this sample project:</strong><br>1. Checking if there is a path from location A to location B<br>2. Finding the fastest route from location A to location B<br>3. Seeing how many places we can travel to based on our starting location</p><p>Let’s start off by creating a graph and vertex class to handle our calculations. You can follow <a href="https://github.com/SarinSwift/GraphProjectAppleMaps"><strong><em>this link</em></strong></a> to get to my GitHub repository for this project!</p><p>The rest of the article will be me explaining the pseudocode that I followed to get to the solutions! Please try to solve them first even if it’s just a few minutes of brainstorming your ideas. It will be helpful to understand the problem and some ideas of solving it first!</p><h4>1. Checking if there is a path from location A to location B</h4><p>Finding a path between 2 vertices can be solved by either using BFS or DFS. <br><em>Check out the </em><a href="https://github.com/SarinSwift/GraphProjectAppleMaps/blob/master/graph.py#L65"><strong><em>code</em></strong></a><strong><em> </em></strong><em>to this problem!</em></p><p><strong><em>Properties: </em></strong><br>visited —Set to store all vertices that will be passed in bfs.<br>queue —Queue for bfs</p><p><strong><em>Pseudocode:</em></strong><br>• Add the <em>source vertex</em> to our empty queue as well as adding it to the visited set.<br>• Loop through the queue while there’re still vertices in it. <br>• dequeue an item from the queue and store it in a variable named curr<br>• check if curr is the <em>destination vertex</em> inputted in the function parameter. If it is so, then we can return true, and our function is complete! <br>• We’re not at the end yet so we would want to continue our bfs algorithm.<br>• Start off by creating another for loop on curr’s neighbors. And only do the following if the neighbor vertex is not in the visited set: <br>enqueue neighbor to our queue, and <br>add neighbor to the visited set. <br>• Once the while loop has finished executing, we can return false since we’ve looped through the connecting vertices in this graph and still have not found the destination vertex!</p><h4>2. Finding the fastest route from location A to location B</h4><p>This problem can be solved by either using BFS or DFS. The functionality is very similar to the solution above🤔 I recommend you try finding the solution to this problem from the pseudocode above before looking below! <br><em>Check out the </em><a href="https://github.com/SarinSwift/GraphProjectAppleMaps/blob/master/graph.py#L94"><strong><em>code</em></strong></a><strong><em> </em></strong><em>to this problem!</em></p><p><strong><em>Properties: <br></em></strong>path_found — Boolean variable that is initially the value False. The value will change once we find the destination vertex!<br>visited—Set to store all vertices that will be passed in bfs.<br>queue —Queue for bfs<br>path — Array to store the connecting paths of vertices from the source to the destination vertex .</p><p><strong><em>Pseudocode:<br></em></strong>• Add the source vertex to our empty queue as well as adding it to the visited set.<br>• Loop through the queue while there’re still vertices in it. <br>• dequeue an item from the queue and store it in a variable named curr<br>• check if curr is the destination vertex inputed in the function parameter. If it is so, we can set path_found to true and break out of the while loop.<br>• Otherwise, we would want to create a for loop on curr’s neighbors. And only do the following if the neighbor is not in the visited set: <br>1. Enqueue neighbor to our queue<br>2. Add neighbor to the visited set<br>3. Set the neighbor’s parent variable to curr vertex<br>• Once the while loop has finished executing, we want to do a check statement if path_found is true. If it’s true, that means we can start appending to our path array! But we must follow these steps carefully:<br>1. Set our curr vertex to be the destination vertex,<br>2. Loop through while curr still has a value so we can: append curr to our path array, and update curr to become curr’s parent.<br>[I just want to note that in this step, with the parent variable, we’re traversing up the tree. And you can visualize it as the root node being the source vertex, and the distance vertex is the last node in the tree.]<br>• Outside the while loop, we can return path in reverse order!</p><h4>3. Seeing how many places we can travel to based on our starting location</h4><p>Since our graph represents vertices as a location, we can implement finding the degree of that vertex! A degree of a vertex simply means the count of the connecting edges. Let’s jump right in our brainstorm! <br><em>Check out the </em><a href="https://github.com/SarinSwift/GraphProjectAppleMaps/blob/master/graph.py#L132"><strong><em>code</em></strong></a><strong><em> </em></strong><em>to this problem!</em></p><p><strong><em>Properties: <br></em></strong>vert_obj —Vertex object from our graph</p><p><strong><em>Pseudocode:<br></em></strong>• Since our vertex class has a property that tracks all it’s neighbors, we can simply return the length of calling the vertex’s neighbors!</p><p>And that will be a wrap on this article on solving problems through graphs! I hope you found value in this blog post and I highly encourage you to try implementing all these methods or even create your own graph theory application!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a8277c6a2ad9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Memory Management in Swift: Heaps & Stacks]]></title>
            <link>https://heartbeat.comet.ml/memory-management-in-swift-heaps-stacks-baa755abe16a?source=rss-ed60eee1cd58------2</link>
            <guid isPermaLink="false">https://medium.com/p/baa755abe16a</guid>
            <category><![CDATA[heartbeat]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[memory-management]]></category>
            <dc:creator><![CDATA[Sarin Swift]]></dc:creator>
            <pubDate>Wed, 05 Jun 2019 15:41:01 GMT</pubDate>
            <atom:updated>2021-10-04T19:07:04.486Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9cHoSNSm1BheV7OKKDruyw.jpeg" /></figure><p>For this article, I want to discuss a couple topics in the iOS world I’ve always found interesting: memory management, heaps, and stacks. I’ve never really understood the difference between them or how heaps and stacks relate to storing memory in Swift.</p><p>So, I decided to do some of my own research and dig deep into memory management in Swift. I hope you’re looking forward to this topic as much as I am! Let’s dive right in.</p><h4>How is Memory Managed in Swift?</h4><p>Swift uses ARC (Automatic Reference Counting). Some of you might find this term familiar. But if not, no worries! We’re all here to learn something new today 🙂.</p><p><strong><em>Reference counting</em></strong> is the process of storing reference counts of initialized objects (normally instances of a class), pointers, or blocks. These are stored in memory and cleaned up—in other words, <em>deallocated—</em>once the objects are no longer needed.</p><p>ARC keeps track of <em>strong references</em> to an object, and when the count goes down to 0 (free from all strong references), the object will automatically deallocate from memory. I specifically say strong references because only strong references increase the count. Whereas <em>weak</em> or <em>unowned</em> <em>references</em> do not increase the count. (We’ll go into more detail about this distinction below.)</p><p>However, if the memory count of an instance never goes down to 0, this causes something that’s called a <em>retain cycle,</em><strong><em> </em></strong>which leads to a<strong><em> </em></strong><em>memory leak</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*us4QKIF8Rl-DjrqIqetEdA.png" /></figure><h3>Memory Leaks</h3><p>A memory leak, as shown above, happens when the objects within the system never get deallocated from memory. This also means that the retain count of these two objects will never come down to 0, and as such they’ll always retain each other in memory!</p><p><strong><em>Retain count — </em></strong>Represents the number of owners for a particular object. <br>Let’s take a small look at this example and see how the retain count increases.</p><pre>class Person {<br>  let name: String</pre><pre>  init(name: String) {<br>    self.name = name<br>  }<br>  deinit {<br>  }<br>}</pre><pre>let person1 = Person(name: &quot;Swifts&quot;)   // retain count: 1</pre><pre>let person2 = person1                 // retain count: 2<br>let person3 = person1                 // retain count: 3</pre><p>The first incremental increase of the retain count happens when we initialize a Person object. We then create two more objects that refer to person1, making the retain count go up to 3 since they’re strong references by default.</p><h4><strong><em>How are objects never deallocated?</em></strong></h4><p>With the help of ARC, Swift automatically deallocates instances that are no longer used / needed (but remember, only when the reference goes down to zero).</p><p>However, if we don’t create our own resources properly (meaning your classes have the same pointer to the same instances), this can cause instances to remain in memory even after their lifecycles have ended.</p><p><a href="https://www.appcoda.com/memory-management-swift/">This article</a> is great to check out if you want to take an in-depth look at how a retain cycle is created in code.</p><h4><strong><em>How can we identify memory leaks?</em></strong></h4><p>Xcode has a built in <em>memory graph debugger</em>. It allows you to see how many reference counts you have on an object and which objects currently exist.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xtwy4HIjY3qKpWQrKa54Dg.png" /><figcaption>read more on memory graph debugger <a href="https://useyourloaf.com/blog/xcode-visual-memory-debugger/">here</a></figcaption></figure><h4><strong><em>How can we fix memory leaks?</em></strong></h4><blockquote>Swift provides two ways to solve reference cycles when working with a class type: weak references, and unowned references . — <a href="https://docs.swift.org/swift-book/LanguageGuide/AutomaticReferenceCounting.html#//apple_ref/doc/uid/TP40014097-CH20-ID48">Swift Docs</a></blockquote><p>Both weak and unowned references do not create a strong hold on objects.</p><p><strong>weak</strong><em> </em><strong><em>— </em></strong>An object that can become nil at any point in time. These types must be optional. And the type must be declared as a variable (not a constant) since the value may be changed (to nil).</p><p><strong>unowned <em>— </em></strong>Assumes that the object will never become nil and is defined using non-optional types.</p><h4><strong><em>Dangers of memory leaks</em></strong></h4><p>Before moving on to memory organization, let’s take a quick look at how memory leaks are dangerous to your app 🆘❗️</p><ul><li><strong>Increases memory footprint of the app:</strong> The action of creating objects is constantly repeating. This causes memory to constantly grow, which leads to memory warnings and app crashes.</li><li><strong>Unwanted side effects:</strong> Say we have an object that starts listening to an event upon creation and stops listening to that event when the object is deallocated. If there’s a memory leak from this object, it will never die and therefore will forever listen in on this event.</li><li><strong>Crashes:</strong> Multiple objects altering the database / user interface /state of app can cause crashes.</li></ul><p>You might be thinking—we already know a lot about memory management in Swift. We do! However, Swift goes deeper and separates the ways in which it stores memory under the hood. Let’s take a look at the two following methods for memory allocation.</p><h3>Heaps and Stacks</h3><h4>Memory Organization</h4><p>Generally speaking, Swift has 2 fundamental parts for memory allocations.<br>Keep in mind that Swift automatically allocates memory in either the heap or the stack.</p><h4><strong>Table of contents</strong></h4><p><strong>A. Heap<br></strong>1. Memory that lives in the heap<br>2. Example of code that gets stored in the heap<br>3. When the heap is used</p><p><strong>B. Stack<br></strong>1. Memory that lives in the stack<br>2. Example of code that gets stored in the stack<br>3. When the stack is used</p><p><strong>C. Heaps and Stacks Data structure<br></strong>1. How memory management ties in to these data structures</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eRUY02ySmSo4TBjm7MrhJg.png" /><figcaption>Stack vs Heap</figcaption></figure><h3>Heap</h3><p>The heap allows you to allocate memory dynamically, unlike the stack. <strong>All objects located on the heap are <em>reference types,</em> such as classes</strong>. Although they are more expensive to use in memory, classes are great to use as an identity and for indirect storage. You can imagine the heap like this: when you create an instance of a class, the memory is thrown right into the heap pile.</p><p><strong><em>Reference types — </em></strong>When instantiating a new object of a class, a reference to that object is created instead of a whole new copy. This means they can be passed around and referenced by many objects! Take a look at this example below.👇🏼👇🏼</p><pre>class Drink {<br>  var type: String<br>  <br>  init(type: String) {<br>    self.type = type<br>  } <br>}</pre><pre>let favoriteDrink = Drink(type: &quot;Chocolate&quot;)<br>let secondFavorite = favoriteDrink</pre><pre>secondFavorite.type = &quot;Matcha&quot;</pre><pre>print(secondFavorite.type)          // &quot;Matcha&quot;<br>print(favoriteDrink.type)           // &quot;Matcha&quot;</pre><p>As you can see above, favoriteDrink is also modified when we change the value of secondFavorite. The reason this happens is because, under the hood, these objects are pointing to the same location in memory. So if you modify a value, all other instances that are pointing to that same object/location will also get modified!💥</p><h4><strong>What goes on in the heap?</strong></h4><p>When you create a new object, some memory gets allocated to the heap. Just like stacks, the memory goes away once it’s not being used. However, in heaps, the memory isn’t tied to functions or programs; instead, the data in the heap is global.</p><p>The heap is less memory efficient because memory is allocated to it by assigning <strong><em>reference pointers</em></strong>. All memory within the heap are instances of reference types only.</p><h4><strong>Conclusions of the heap</strong></h4><ul><li>It’s more dynamic but less efficient than the stack.</li><li>Can grow and shrink in size.</li><li>Stores reference types such as classes.</li><li>Goes through 3 steps: a<em>llocation</em>, <em>tracking reference counts</em>, and <em>deallocation</em>. As such, this process is less efficient when compared to stacks.</li></ul><h3>Stack</h3><p><strong>Stacks are where all <em>value types</em> are stored</strong>. When a function is called, all local instances in that function will be pushed on to the current stack. And once the function has returned, all instances will have been removed from the stack.</p><p><strong><em>Value types — </em></strong>Independent instances that hold data in their own memory allocation. This is helpful in that, when you modify a value, you won’t accidentally change the value of another instance. Such as this example below.👇🏼👇🏼</p><pre>var firstValue = 22<br>var secondValue = firstValue</pre><pre>secondValue += 2</pre><pre>print(secondValue)           // 24<br>print(firstValue)            // 22</pre><p>Use value types when you want to compare data of the instances with the == operator or when you want your copies to have independent states. Some examples of value types are <em>arrays</em>, <em>strings</em>, <em>dictionaries</em>, <em>structs</em>, <em>enums,</em> etc.</p><h4><strong>What goes on in the stack?</strong></h4><p>All of our allocation happens in what’s called a <strong><em>function call stack</em></strong>. When a function exits, all the data will pop off the stack. Data will only exist while the function is still running.</p><p>Let’s take a look at what our function call stack looks like, going through the code below along with the diagram!</p><pre>struct Point {<br>  var x: Double<br>  var y: Double<br>}</pre><pre>// step1<br>let point1 = Point(x: 0, y: 0)</pre><pre>// step2<br>var point2 = point1</pre><pre>// step3<br>point2.x = 2</pre><pre>// step4<br>// completed all tasks above</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Va7bN3l4FGp-itep-COTQw.png" /><figcaption>Idea based from: <a href="https://developer.apple.com/videos/play/wwdc2016/416/">WWDC talk</a></figcaption></figure><p>Before our code runs, we allocate space for point1 and point2 instances.</p><p><strong><em>Step 1 — </em></strong>When we instantiate point1, we’re pushing it onto the stack.</p><p><strong><em>Step 2 — </em></strong>point1 is assigned to point2, which means a new copy of point1 is created and pushed onto the stack.</p><p><strong><em>Step 3 — </em></strong>Simply changing the value x for point2. Notice that only point2 is altered and not point1☝🏼.</p><p><strong><em>Step 4 — </em></strong>Once we’re done executing these tasks(functions), point1 and point2 are deallocated from memory and our stack now contains no data.</p><p>If we have a function that calls another function, the execution of all functions remains suspended until the very last function returns its values. Very interesting how so similar this is to recursion! Turns out, recursion actually uses a stack implementation as well.</p><h4><strong>Conclusions of the stack</strong></h4><ul><li>More efficient when allocating and deallocating data.</li><li>Stacks store value types, such as structs and enums.</li><li>Data stored in the stack is only there temporarily until the function exits and causes all memory on the stack to be automatically deallocated.</li><li>Makes memory lookup and access very fast from how well it is organized.</li><li>The most frequently reserved block is the first to be freed.</li></ul><h4>Heaps and Stacks Data Structure</h4><p>The ways in which heaps and stacks are used in Swift to store memory have a lot of similarity with how we use data structures. In the next article, we’re going to see what these data structures do and how both are implemented in Swift!</p><p>That’s it for today’s article! Thank you so much for sticking with me. I hope you gained some deeper understanding for iOS development and how memory gets stored in Swift. If you have any questions, comments, or concerns, please feel free to reach out to me, and I’ll get back to you as soon as I can.🙂</p><p><strong>Good reads to check </strong>💯<br><a href="https://www.gribblelab.org/CBootCamp/7_Memory_Stack_vs_Heap.html">Stack vs Heap</a> — GribbleLab<br><a href="https://swiftrocks.com/memory-management-and-performance-of-value-types.html">Memory Management</a> — SwiftRocks</p><blockquote>Thank you for checking out this blog post!</blockquote><blockquote>If you have any questions or comments, please feel free to reach out to me. And don’t forget to give this article some claps! 👏🏼*up to 50x*👏🏼 if you found it helpful.</blockquote><p><em>Editor’s Note: </em><a href="https://heartbeat.comet.ml/"><em>Heartbeat</em></a><em> is a contributor-driven online publication and community dedicated to providing premier educational resources for data science, machine learning, and deep learning practitioners. We’re committed to supporting and inspiring developers and engineers from all walks of life.</em></p><p><em>Editorially independent, Heartbeat is sponsored and published by </em><a href="http://comet.ml/?utm_campaign=heartbeat-statement&amp;utm_source=blog&amp;utm_medium=medium"><em>Comet</em></a><em>, an MLOps platform that enables data scientists &amp; ML teams to track, compare, explain, &amp; optimize their experiments. We pay our contributors, and we don’t sell ads.</em></p><p><em>If you’d like to contribute, head on over to our</em><a href="https://heartbeat.fritz.ai/call-for-contributors-october-2018-update-fee7f5b80f3e"><em> call for contributors</em></a><em>. You can also sign up to receive our weekly newsletters (</em><a href="https://www.deeplearningweekly.com/"><em>Deep Learning Weekly</em></a><em> and the </em><a href="https://info.comet.ml/newsletter-signup/"><em>Comet Newsletter</em></a><em>), join us on</em><a href="https://join.slack.com/t/fritz-ai-community/shared_invite/enQtNTY5NDM2MTQwMTgwLWU4ZDEwNTAxYWE2YjIxZDllMTcxMWE4MGFhNDk5Y2QwNTcxYzEyNWZmZWEwMzE4NTFkOWY2NTM0OGQwYjM5Y2U"><em> </em></a><a href="https://join.slack.com/t/cometml/shared_invite/zt-49v4zxxz-qHcTeyrMEzqZc5lQb9hgvw"><em>Slack</em></a><em>, and follow Comet on </em><a href="https://twitter.com/Cometml"><em>Twitter</em></a><em> and </em><a href="https://www.linkedin.com/company/comet-ml/"><em>LinkedIn</em></a><em> for resources, events, and much more that will help you build better ML models, faster.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=baa755abe16a" width="1" height="1" alt=""><hr><p><a href="https://heartbeat.comet.ml/memory-management-in-swift-heaps-stacks-baa755abe16a">Memory Management in Swift: Heaps &amp; Stacks</a> was originally published in <a href="https://heartbeat.comet.ml">Heartbeat</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Easy Google Maps Setup Tutorial— Swift 5]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/better-programming/easy-google-maps-setup-tutorial-swift-4-f6d5c093817e?source=rss-ed60eee1cd58------2"><img src="https://cdn-images-1.medium.com/max/916/1*Ccid6lrryNpo_Om_jH_SAQ.png" width="916"></a></p><p class="medium-feed-snippet">A straight forward, step-by-step guide to integrating Google Maps</p><p class="medium-feed-link"><a href="https://medium.com/better-programming/easy-google-maps-setup-tutorial-swift-4-f6d5c093817e?source=rss-ed60eee1cd58------2">Continue reading on Better Programming »</a></p></div>]]></description>
            <link>https://medium.com/better-programming/easy-google-maps-setup-tutorial-swift-4-f6d5c093817e?source=rss-ed60eee1cd58------2</link>
            <guid isPermaLink="false">https://medium.com/p/f6d5c093817e</guid>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[maps]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Sarin Swift]]></dc:creator>
            <pubDate>Sat, 25 May 2019 23:49:34 GMT</pubDate>
            <atom:updated>2019-05-31T15:08:03.536Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Doubly Linked Lists — Swift 4]]></title>
            <link>https://medium.com/@sarinyaswift/doubly-linked-lists-swift-4-ae3cf8a5b975?source=rss-ed60eee1cd58------2</link>
            <guid isPermaLink="false">https://medium.com/p/ae3cf8a5b975</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[mobile]]></category>
            <dc:creator><![CDATA[Sarin Swift]]></dc:creator>
            <pubDate>Thu, 02 May 2019 04:43:56 GMT</pubDate>
            <atom:updated>2019-06-18T16:19:51.960Z</atom:updated>
            <content:encoded><![CDATA[<h3>Doubly Linked Lists — Swift 4</h3><h4>GetAtIndex, insertAtIndex, append, prepend</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rkn3q6HJoEkRO4T_SVlyuw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OSshaenuUBW_wxIv7c3FgQ.png" /><figcaption>Doubly Linked List Diagram</figcaption></figure><p>This diagram represents our linked list we will be working with! Each rectangle represents a node which has 3 slots in it. The middle slot represents value of the node, the left slot represents the previous pointer, and the right slot represents the next pointer. In addition to that, our linked list will keep count of a head and a tail.</p><p>Make sure to check out my singly linked list article <a href="https://medium.com/@sarinyaswift/linked-list-implementation-in-swift-4-caea34cbdada">here</a> for previous references!😃 There, I go in depth of how to create a singly linked list class as well as a node class to start implementing the different methods within it.</p><p><em>How are doubly linked lists different from singly linked lists?</em> Doubly has a previous pointer which points to its previous node! This can be favorable based upon what type of actions we want to do on our data structure which we will go into furthermore in this article.⏬✔️</p><h4>Table of Contents</h4><ol><li><a href="https://medium.com/p/ae3cf8a5b975#a91f"><strong>Pros and Cons of a Doubly LinkedList</strong></a></li><li><a href="https://medium.com/p/ae3cf8a5b975#b829"><strong>Creating the Node Class Using Generics</strong></a></li><li><a href="https://medium.com/p/ae3cf8a5b975#1996"><strong>Creating the LinkedList Class Using Generics</strong></a></li><li><a href="https://medium.com/p/ae3cf8a5b975#1027"><strong>Methods in Doubly LinkedList class:</strong></a><br>• Append<br>• Prepend<br>• Items<br>• Get node at index<br>• Insert at index</li><li><a href="https://medium.com/p/ae3cf8a5b975#91da"><strong>Examples of Using Doubly Linked List in Real Life</strong></a></li><li><a href="https://medium.com/p/ae3cf8a5b975#00c5"><strong>Stretch Challenges!</strong></a><strong><br></strong>• Delete all nodes in the linked list<br>• Inserting a node after a specific node<br>• Print out the linked list in order<br>• Print out the linked list in reverse order</li></ol><h4>Pros and Cons of a Doubly Linked List</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SLpshK2cYwgSQo8-RDfrUA.png" /></figure><h4><strong>Node class</strong></h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dc9cd95edb117ac85ca33e7e16648462/href">https://medium.com/media/dc9cd95edb117ac85ca33e7e16648462/href</a></iframe><p>As you can see in this Node class above, each node holds exactly 3 variables; a value(data), a <em>next</em> which will hold the node after it, and a <em>prev</em> which will hold the node before it.</p><p><strong>Generics</strong></p><blockquote>Generic code enables you to write flexible, reusable functions and types that can work with any type, subject to requirements that you define. — Swift Docs</blockquote><p>Swift Array and Dictionary types are generic collections.<br>In our case, we would also want to create our linked list class using generics so we can create nodes with whichever type we want such as Integers, Floats, Doubles, Strings, Tuples, or even our own Models!</p><h4><strong>Linked List class</strong></h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bafcf247116db5997ae693e434ec0ebc/href">https://medium.com/media/bafcf247116db5997ae693e434ec0ebc/href</a></iframe><p>This linked list class will contain properties of the head, tail, and size. This <em>size</em> value will be helpful when we want to find the length of the entire linked list.</p><p>Now that we have our foundation written down, we can start implementing different methods to our LinkedList class👇🏼👇🏼👇🏼</p><h4>Methods in DoublyLinkedList class</h4><p>I highly recommend to try coding these functions or writing down pseudocode before looking at the solutions!! 📝 ✍🏼<br>Don’t forget to keep account for both next pointers and previous pointers while implementing the following methods.</p><ul><li><strong>Append</strong></li></ul><p><em>Adding a new item to the end of the linked list.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e2478246d580a522a2b28d45a44eb47d/href">https://medium.com/media/e2478246d580a522a2b28d45a44eb47d/href</a></iframe><p>This is where <em>self.size </em>will be used and updated!</p><ol><li>Create a new node from the value passed in the parameter</li><li>Create a guard statement to make sure the head value is not nil in order to continue lines after 12.</li><li>If the head is nil, meaning our linked list is empty, we initialize the head and tail to be the new node created on line 3.</li><li>Now that we are sure our linked list isn’t empty, we know there is a tail value. So we set the tail’s next pointer to be <em>newNode</em>. We also give <em>newNode</em> a previous pointer to our tail. Lastly, is to update the tail to become the <em>newNode</em>.</li><li>Incrementing our size by 1 since we just added a new member to our list family. 😲😄</li></ol><ul><li><strong>Prepend</strong></li></ul><p><em>Adding a new item to the beginning of the linked list.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/042e9604e850020fcfbcbc452876a1f5/href">https://medium.com/media/042e9604e850020fcfbcbc452876a1f5/href</a></iframe><ol><li>Create a new node from the value parameter</li><li>Using a guard statement to make sure there is a head value or else lines 8–11 will get executed.</li><li>Initializing our head and tail to be <em>newNode</em> without having to change or add any pointers.</li><li>Now that the case of the linked list isn’t empty, we go ahead and do the following:<br>Setting the head’s previous pointer to be <em>newNode<br></em>Giving <em>newNode</em> a next pointer to our head<br>And finally updating the head to our first node(<em>newNode</em>)</li><li>Incrementing our size by 1 since we just added a new member to our list family. 😲😄</li></ol><ul><li><strong>Items</strong></li></ul><p><em>Returning all items in the linked list as an array of values sorted from the head to tail.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d5a7ebf96c2e390b3eba09cee0593d3b/href">https://medium.com/media/d5a7ebf96c2e390b3eba09cee0593d3b/href</a></iframe><ol><li>If the linked list is empty, we return an empty array</li><li>Create an empty array where we will be appending all the node values</li><li>Loop through the linked list starting from self.head. <br>In the while loop we first append the current node’s value, and then update <em>curr</em> to become the next node.</li><li>Once we hit the end of the linked list, we can return the array which is now filled with all the values of nodes in the linked list!</li></ol><ul><li><strong>Insert at index:</strong></li></ul><p><em>Inserting a node at the given position we would want to insert it at.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cfa53bc7ceab36aa6f28080d046c0b50/href">https://medium.com/media/cfa53bc7ceab36aa6f28080d046c0b50/href</a></iframe><p>Don’t be alarmed by this huge chunk of code! We’ll get through this together step by step and see how this magic all happens.🔗🔗</p><p>1. We first need to check the input index must be in range of our items in the linked list. Let’s say we have 3 nodes in our linked list, the indexes we can only go up to is 3. If given index is larger than 3, we’ll return out of the function with a print statement saying the index is out of bounds.</p><p>⚠️Before going into steps 2, 3, and 4, we must know there are 3 possibilities of where we want to insert the node. <br> — Inserting at the front: changing self.head<br> — Inserting at the end: changing self.tail <br> — Inserting between 2 nodes: changing next and previous reference pointers.<br>We would want to check for these cases separately so our code is more efficient!</p><p>2. <em>index == 0</em> means we’re inserting in front of our list. <br>Here’s what’s going on in the prepend method. (Order matters!☝🏼)<br>- Set the current head’s previous pointer to our newNode<br>- Set our newNode’s next pointer to the self.head. We do not need to set newNode’s previous pointer since it’s set by default to nil<br>- Change the head to be our newNode!!</p><p>3. <em>index == self.size</em> means we‘re inserting to the end of our list.<br>Here’s what’s going on in the append method. (Order matters!☝🏼)<br>- Set the current tail’s next pointer to our newNode<br>- Set our newNode’s previous pointer to the current tail<br>- then we change the tail!</p><p>4. index is somewhere between 2 nodes which means we’ll have to traverse the linked list until we get to the desired index.<br>- 1: Create a new node with the desired value<br>- 2: Loop through the linked list, updating our <em>curr</em> node to become the node right at the index we would want to insert <em>newNode</em><br>- 3: Attaching our current’s previous’s next pointer to <em>newNode</em>.<br>And also attaching our <em>newNode</em>’s previous pointer to our current’s previous node.<br>Now we can reassign current’s previous pointer to <em>newNode</em>.<br>And our <em>newNode</em>’s next pointer to the current node.<br>- 4: Incrementing self.size by 1. And we’re only doing this step in the else clause because both append and prepend methods already cover the incrementation.</p><ul><li><strong>Get node at index</strong></li></ul><p><em>This method simply returns the value of the node at the given index.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ea317a4a8b179820dec8595697e1d4cc/href">https://medium.com/media/ea317a4a8b179820dec8595697e1d4cc/href</a></iframe><p>1. Checks that the input index is in the range from 0 to self.size. Or else, we will return nil since there are no values at that invalid index.<br>2. start from self.head and traverse through the linked list. If say the index was 1, then we update ‘curr’ to the next node 1 time. Likewise, if the index was 0, the code won’t execute the for loop at all (0 times).<br>3. Lastly, we return the value of that current node because it is correctly at the index we are looking for.</p><h4>Examples of Using Doubly Linked Lists in Real Life</h4><p>• Creating a music playlist 🎶🎵🎶. <a href="https://medium.com/journey-of-one-thousand-apps/data-structures-in-the-real-world-508f5968545a">This article</a> even gives you a coding example on how to implement your own class!<br>• Drawing from a deck of cards. The nodes can represent the rank, and color of one card. <br>• And finally, the undo and redo functionality on a browser!! This is where you can reverse the node to get to the previous page.</p><h4>Stretch Challenge Methods</h4><ol><li>deleteAll(): Deletes all the nodes in the linked list</li><li>insertAfter(_ value: T, after: T): Takes in the value you want to insert and, a value of the node you want to insert right after</li><li>listForward(): prints out the linked list node’s values from front to back</li><li>listBackward(): prints out the linked list node’s values from back to front</li></ol><p>I hope you found value in this blog post and I highly encourage you to try implementing all these methods in a Swift playground</p><blockquote><em>Thank you for checking out this blog post!</em></blockquote><blockquote><em>If you have any questions or comments, please feel free to reach out to me. And don’t forget to give this article some claps! 👏🏼*up to 50x*👏🏼 if you found it helpful.</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ae3cf8a5b975" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Linked List Implementation in Swift 4]]></title>
            <link>https://medium.com/@sarinyaswift/linked-list-implementation-in-swift-4-caea34cbdada?source=rss-ed60eee1cd58------2</link>
            <guid isPermaLink="false">https://medium.com/p/caea34cbdada</guid>
            <category><![CDATA[swift-4]]></category>
            <category><![CDATA[singly-linked-list]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[data-structures]]></category>
            <dc:creator><![CDATA[Sarin Swift]]></dc:creator>
            <pubDate>Thu, 14 Mar 2019 17:30:06 GMT</pubDate>
            <atom:updated>2019-05-28T20:01:07.709Z</atom:updated>
            <content:encoded><![CDATA[<h3>Linked List Implementation — Swift 4</h3><h4>Append, Prepend, Remove, Find, and Replace</h4><p>As you may have heard the term linked list pop in every now and then. It’s a form of data structure that can store a collection of items. Linked list consists of a group of nodes together to represent a sequence, relative of the same type.<br>If you are here to learn how to implement linked lists in Swift and learn some tips, you’re in the right place!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s5ijOdLiHuB6447mHKEmeQ.png" /><figcaption>each rectangle represents a node</figcaption></figure><p>As you might have guessed, the picture above demonstrates a linked list. In this case, the linked list contains many nodes, a head, and a tail. The head represents the beginning node and the tail represents the last node in the linked list. Each node contains a value(data) and a next referencing to a new node.</p><p>Node class contains: value, and next</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ra-PkUH8NiLSNz5jujUnsA.png" /></figure><p>Linked List class contains: head, and tail</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pq6vvvxWtaB2l_0ujB-vsg.png" /></figure><p>We conform to the ‘Equatable protocol’ in both classes. <br>Equatable protocol — has a constraint where you are able to check equality between objects of the same type. Thus, allows us to perform the == operation on our T type, and on our Nodes!!</p><p>Now that we have our foundation written down, we can start implementing different methods to our LinkedList class👇🏼👇🏼👇🏼</p><h4>Methods in LinkedList class</h4><p>I highly recommend to try coding these functions or writing down pseudocode before looking at the solutions!! 📝 ✍🏼</p><ul><li><strong>Prepend (Insert at beginning)<br>Runtime: O(1)</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iSPziZCPfvqMEQrLD9XPxg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oxqq8VIUUI--4nTnaeaAaA.png" /></figure><ol><li>Create a new node from our input value</li><li>If our linked list is empty, assign head and tail to our new node</li><li>If our linked list is not empty:<br>assign our new node’s next pointer to self.head<br>and update the head pointer to be our new node</li></ol><ul><li><strong>Append at end<br>Runtime: O(1)</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9eXwe43aJoaGIZZmDvplYw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AfZfuY_1esSumbShFmDZLg.png" /></figure><ol><li>Create a new node from our input value</li><li>If our linked list is empty, assign head and tail to our new node</li><li>If our linked list is not empty:<br>set the tail’s next pointer to the new node<br>and update the tail pointer to be our new node</li></ol><ul><li><strong>Remove a value<br>Runtime: O(n) where n is the number of nodes we have to traverse through</strong></li></ul><p>In the code below, we are checking for the following cases where we want to remove the node:<br>case1 : is the tail<br>case2 : is the head<br>case3 : is in between nodes<br>case4 : is the only node (both head and tail)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tpAsJcsMbjXb-wOLN6LpNA.png" /><figcaption>removing last node (lines 64–70)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xLPZ8ik5GTipjsQ9FANDvg.png" /><figcaption>removing first node (line 77)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mm1A_yRE5SWHCtq29hRA1A.png" /><figcaption>removing middle node (line 70)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ABWQ9XXvC0iZjQM0qVxHRQ.png" /><figcaption>removing single node (lines 71–77)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rJA5ABpa0UaRqV7EdSFjKg.png" /></figure><ol><li>Create variables so we have access to the current node and previous node</li><li>Traverse through the linked lists while current is not nil</li><li>Found a node that is equal to our input value!!</li><li>Checking the previous node has a value</li><li>Deleting a node at the end of a linked list<br>set self.tail to be the previous node</li><li>Change pointer of prev’s next to curr’s next</li><li>Else, previous node is nil. And we’re deleting a node at the end of a linked list.<br>set self.tail to be the previous node</li><li>Changing self.head to be the current’s next node</li><li>Haven’t found the item yet, so we keep looping through and checking the next node.</li></ol><ul><li><strong>Length<br>Runtime: O(n) where n is the number of nodes in the linked list.<br>However, the runtime can be O(1) if we have another value in the linked list class that keeps count of items as we insert/append, or remove.</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fHnbuErq55O2l7bXxkN_kA.png" /></figure><ol><li>If the linked list is empty, return 0 and leave the function</li><li>Create variables for count and current node</li><li>Traverse through the linked list while curr isn’t nil</li><li>Increment count by 1 and check on the next node</li><li>Return the count!</li></ol><ul><li><strong>Last element<br>Runtime: O(1)</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xk6T52RyBisp_YmfA9Ni6g.png" /></figure><p>Returns the last element in our linked list.</p><ul><li><strong>Find<br>Runtime: O(n) where n is the number of nodes we traverse through.</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0iSDBiFGgX9ZxjzdMd2RqQ.png" /></figure><p>Here we are traversing through the linked list until we find a node that is equal to our input value. <br>This method returns the value of that node being that it is found, else, will return nil</p><ul><li><strong>Replace an old item with a new item<br>Runtime: O(n) where n is the number of nodes we traverse through.</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8zvID-92IkwBZGaGtp2Uhg.png" /></figure><ol><li>Create a variable to keep count of the current node</li><li>Traverse through the linked list while curr isn’t nil</li><li>We’ve found the node! So replace the curr’s value with the new input value and return out of the function</li><li>Haven’t found the node yet, so we loop to check the next node</li></ol><h3>Testing</h3><p>Now that we have our foundation class written down and functioning, let’s go ahead and test to see if these methods actually work 🤔🤔</p><p><strong>Append<br></strong>Start off by instantiating an empty linked list and appending items to it.</p><pre>let ll = LinkedList&lt;String&gt;()<br>ll.append(value: &quot;apple&quot;)<br>ll.append(value: &quot;butter&quot;)<br>ll.append(value: &quot;cinnamon&quot;)</pre><p>If we write a print statement checking the head and tail, it should print out “apple” and “cinnamon” respectively.</p><pre>print(ll.head?.value ?? &quot;no head found&quot;)   // apple<br>print(ll.tail?.value ?? &quot;no tail found&quot;)   // cinnamon</pre><p><strong>Remove<br></strong>Removing something from the start of a linked list should change the head pointer…</p><pre>ll.remove(value: &quot;apple&quot;)<br>print(ll.head?.value ?? &quot;nothing found&quot;)    // butter<br>print(ll.tail?.value ?? &quot;no tail found&quot;)    // cinnamon</pre><p><strong>Replace<br></strong>Replaces the old value with our new value and should print out the new value.</p><pre>ll.replace(old: &quot;cinnamon&quot;, new: &quot;chocolate&quot;)<br>print(ll.tail?.value ?? &quot;no tail found&quot;)    // chocolate</pre><p>These are just some methods of a linked list class implemented in Swift. Go ahead and try these out in a Swift playground and see the magic! Ѻ→Ѻ→Ѻ<br>I’m sure there are more methods out there and would love to see anyone share them down below😃🤓</p><blockquote><em>Thank you for checking out this blog post! If you have any questions or comments, please feel free to reach out to me 🙂 And don’t forget to give this article some claps! 👏🏼👏🏼*up to 50x*👏🏼 if you found it helpful.💡</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=caea34cbdada" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Easy TableView Setup Tutorial — Swift 4]]></title>
            <link>https://medium.com/@sarinyaswift/easy-tableview-setup-tutorial-swift-4-ad48ec4cbd45?source=rss-ed60eee1cd58------2</link>
            <guid isPermaLink="false">https://medium.com/p/ad48ec4cbd45</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift-4]]></category>
            <category><![CDATA[programming-languages]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios-apps]]></category>
            <dc:creator><![CDATA[Sarin Swift]]></dc:creator>
            <pubDate>Wed, 23 Jan 2019 04:16:17 GMT</pubDate>
            <atom:updated>2019-04-30T17:53:00.632Z</atom:updated>
            <content:encoded><![CDATA[<h3>Easy TableView Setup Tutorial — Swift 4</h3><h4>A straight forward step by step guide done programmatically.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hy2mLW_I4zkTgfsa-354kw.png" /></figure><p>Hi everyone! Today, I will be showing you a step by step tutorial on how to setup a TableView programmatically as well as using the delegate and datasource protocols in Swift 4.2. I hope this tutorial serves as purposeful to you in your projects and let’s jump right in! 😃</p><h4>Step 1: Create a ViewController.swift file</h4><p>This will serve as the View Controller where we add our tableView subview and manage the UIKit app’s interface.</p><pre>class ViewController: UIViewController {</pre><pre>}</pre><h4><strong>Step 2: In our ViewController class, instantiate a UITableView object</strong></h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e36f72a61403103ea8298d7933700a60/href">https://medium.com/media/e36f72a61403103ea8298d7933700a60/href</a></iframe><p>This is how we create a TableView object and set all the requirements for them within this scope.</p><h4>Step 3:<strong> Setup the tableView and add constraints!</strong></h4><p>We add views and set constraints to them with the ViewDidLoad method. This method is called after the view has been loaded. <br>Instead of putting all the code inside viewDidLoad, we’re going to make this more readable by creating a function for setting up the tableView. 🙂</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/394c5244abbcd15311bc0f9c03ea8b3c/href">https://medium.com/media/394c5244abbcd15311bc0f9c03ea8b3c/href</a></iframe><p>Once completed, try running the app and you should see the following!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/250/1*boG8jcMXCFfzmr1MJM5TDw.png" /></figure><h4>Step 4:<strong> Conform to UITableViewDelegate and UITableViewDataSource</strong></h4><p>According to Apples documentation — The <em>delegate</em> manages table row configuration and selection, row reordering, highlighting, accessory views, and editing operations.<br>While the <em>data source</em> provides information that UITableView needs to construct tables and manages the data model when rows of a table are inserted, deleted, or reordered.<br>Once we inherit from the delegate and datasource in our class, we then add the protocol stubs, and assign our tableView to the delegate and datasource methods. ( tableView.delegate = self )</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0dc575ee96b547c23628961b9927ae4d/href">https://medium.com/media/0dc575ee96b547c23628961b9927ae4d/href</a></iframe><p>1. We return 10 numbers of cells in the tableView<br>2. Create a tableViewCell to populate the screen.<br>Currently everything is configured through defaults, so we cannot change the views unless we create our own UITableViewCell class! 👇🏼👇🏼</p><h4>Step 5: Create our own custom subclass of UITableViewCell</h4><p>Note that this is of type UITableViewCell. According to apples documentation — This class includes properties and methods for setting and managing cell content and background (including text, images, and custom views), managing the cell selection and highlight state, managing accessory views, and initiating the editing of the cell contents.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/878e020baf57ce993b2aa94748e76e88/href">https://medium.com/media/878e020baf57ce993b2aa94748e76e88/href</a></iframe><p>Because UIView adopts the NSCoding protocol, it requires an init(coder:) initializer. And since we’re implementing init(style:reuseIdentifier:) , our class is no longer inheriting from the super initializers resulting in the implementation of the code on line 7 👆🏼</p><h4>Step 6: Register the new cell class</h4><p>Once we’ve added a TableViewCell class, we can now make our ViewController inherit this cell. And, in order to make that, we’ll need to do some small changes in setupTableView method and datasource protocol.</p><pre>func setupTableView() {<br>    ...<br>    tableview.register(ThirtyDayCell.self, forCellReuseIdentifier: &quot;cellId&quot;) <br>    ...<br>}</pre><pre>...</pre><pre>func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {<br>    let cell = tableview.dequeueReusableCell(withIdentifier: &quot;cellId&quot;, for: indexPath) as! ThirtyDayCell</pre><pre>    ...<br>}</pre><p>The tableViewCells right now are very small, to offset this I will be adding a delegate method to increase the height for all cells.</p><pre>func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -&gt; CGFloat {<br>    return 100<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/250/1*MqPeWkTfoSeeWw_RMOH_Dg.png" /><figcaption>You should end up with something like this!</figcaption></figure><h4>Step 7: Add content to our ThirtyDayCell class</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/250/1*dnwKu7se7znOWCschDkp8w.png" /></figure><p>With the above photo being what we need to end up with, we need to instantiate a UIView for the background color and then a UILabel to represent each day.</p><ul><li><strong>Instantiate the UIView and UILabel</strong></li></ul><p>In order to have this rounded cell look, we are going to add a UIView and that will represent the orange colored cells as you can see in the above picture!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5eb33e0b7fc93e8fcf65894757d31cbb/href">https://medium.com/media/5eb33e0b7fc93e8fcf65894757d31cbb/href</a></iframe><ul><li><strong>Setup the UIView and add constraints!<br></strong>This step is similar to setting up the tableView but instead we set up the view in our override init method.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/96837962258a03c68ae64cd20a6f750c/href">https://medium.com/media/96837962258a03c68ae64cd20a6f750c/href</a></iframe><ul><li><strong>Setup the UILabel inside the UIView and add constraints!</strong></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5855078045873c31c2fbdd8667bf0e49/href">https://medium.com/media/5855078045873c31c2fbdd8667bf0e49/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/250/1*ywE1fARSk1blblp5of5rUw.png" /></figure><p>As you can notice, there is a small line that goes across the screen right under each of our cells. By default the tableView separator color is set to grey. We can change this easily in our instantiation of the tableView</p><pre>let tableview: UITableView = {<br>    ...<br>    tv.separatorColor = UIColor.white<br>    return tv<br>}()</pre><h4>Step 8: Customize the data in each of our cells in this tableView(_:cellForRowAt:) method</h4><p>Once we type cast the cell to ThirtyDayCell, we can access all the properties and methods within that class! And with this in mind, we’re going to change the dayLabel’s text.</p><pre>func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {<br>    let cell = tableview.dequeueReusableCell(withIdentifier: &quot;cellId&quot;, for: indexPath) as! ThirtyDayCell<br>    cell.backgroundColor = UIColor.white<br>    cell.dayLabel.text = &quot;Day \(indexPath.row+1)&quot;<br>    <br>    return cell<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/250/1*dnwKu7se7znOWCschDkp8w.png" /></figure><blockquote>Completed!!</blockquote><blockquote>Thank you for checking out this blog post! If you have any questions or comments, please feel free to reach out to me 🙂 And don’t forget to give this article some claps! 👏🏼👏🏼*up to 50x*👏🏼 if you found it helpful.💡</blockquote><p>Thanks to <a href="https://medium.com/u/f9dcad8d0875">Vincenzo Marcella</a>, <a href="https://medium.com/u/d5fe5a88b33a">Medi Assumani</a>, and <a href="https://medium.com/u/178baca9fa44">Noah Woodward</a></p><figure><a href="https://usejournal.com/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=guest_post_image"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f2IVAl0TbsfES9cFGYr40g.png" /></a></figure><p><strong>This story is published in Noteworthy, where 10,000+ readers come every day to learn about the people &amp; ideas shaping the products we love.</strong></p><p><strong>Follow our publication to see more product &amp; design stories featured by the </strong><a href="https://usejournal.com/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=guest_post_text"><strong>Journal</strong></a><strong> team.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ad48ec4cbd45" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Software Product Development]]></title>
            <link>https://uxdesign.cc/software-product-development-d4fbcc7dc67b?source=rss-ed60eee1cd58------2</link>
            <guid isPermaLink="false">https://medium.com/p/d4fbcc7dc67b</guid>
            <category><![CDATA[product-development]]></category>
            <category><![CDATA[design]]></category>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[app-development]]></category>
            <dc:creator><![CDATA[Sarin Swift]]></dc:creator>
            <pubDate>Wed, 12 Dec 2018 23:21:59 GMT</pubDate>
            <atom:updated>2018-12-13T04:30:13.747Z</atom:updated>
            <content:encoded><![CDATA[<h3>Software product development</h3><h4>An iteration on creating the product</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*Gv3cCeJTzOkzhzKzW2qyCA.png" /><figcaption>By Tatiana Shulgina</figcaption></figure><p>Have you ever thought about traveling with your best friend or family and being able to know exactly where they are at every point in the trip? Look no further. There has been various occasions where people have wasted time just to catch up with others who may be arriving to the destination late or had changed routes and made the trip more complicated for others. What if there was an application to help solve that problem? From iterating over the different possibilities to help tackle this problem, we came up with this solution:</p><blockquote><em>An app for users to keep track of each other where they are in real time.</em></blockquote><p>From doing research, we have found several apps that tackle similar problems. The following are some example apps:<br><em>Follow: Drive together — O</em>ther users can follow the same route as the leader’s<br><em>Roadtrippers</em> — Users can view different destinations along the route and pin them to their map.<br><em>inRoute Route Planner </em>— Allows users to choose routes based on their preferences<br>The following will be our iteration process in <em>creating and improving</em> our product.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*tn2e9_brHahZhb7n9axiaQ.png" /><figcaption>from: <a href="https://2012-2017.usaid.gov/div/apply">USAID</a></figcaption></figure><h3>Strategies</h3><ul><li>Pair programming</li><li>Retrospective meetings</li><li>Wireframes / Design (UI/UX)</li><li>User journeys</li><li>User interviews</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*bTYgx0KQO76_HnPNnCF_OA.jpeg" /><figcaption>By submain.com</figcaption></figure><h4>Six common issues with pair programming.</h4><p><strong>and tips for improving</strong></p><ul><li>Hard to meet up<br>Sometimes we have different schedules, and it can be hard to settle on times for meeting up and working on the project together. To make meeting up go smoothly, we both had a common agreement that we would sacrifice time for the meetings and pair programming.</li><li>One person more technical than the other<br>Be patient with people you’re working with. Understand what they are struggling with then demo and explain parts of the code and also always know how to limit the scope down to be something for both to work on.</li><li>Indecision on idea <br>Try to understand the goals on both sides of the team and write down as many topics as you can. One thing that really helps is to just talk over every possible choice. sometimes just talking can spark up more ideas and I guarantee you, you will get to know a lot about your team member and what both sides are most passionate about.</li><li>the goals of your partner<br>Using a problem tree / Opportunity tree<br>Write a decision document listing options with pros and cons<br>Go out to mentors or instructors to check further about the idea</li><li>Indecision on Stack &amp; Tech<br>Over scoping is the biggest risk<br>Choose the most logical solution based on the people in the room and their technical skills</li><li>Indecision on design <br>Pick an <em>area owner </em>for UX/UI — A designated lead of design who makes the final calls</li><li>Lack of accountability &amp; follow through<br>Pair programming — One <a href="https://pdfs.semanticscholar.org/1d4c/7da6969ad0df86aa1d81274305fddc1e20e0.pdf">research</a> stated “students that worked in pairs passed 15% more of the instructor’s test cases.” <br>Celebrate wins!<br>Plan to share all tasks 50/50<br>Set force meetings with an advisor. So you can set aggressive deadlines for yourself.<br>Set small and agile goals</li></ul><h4>Retrospective Meeting Agenda</h4><p>My team mate and I decided to cover these following points in every meeting:</p><ul><li>Define done (shipped, finished the code, completed wireframes)</li><li>Be able to demo the finished task</li><li>Talk about what went well last week and what went poorly</li><li>Acknowledge the other and give shoutouts</li><li>Plan for future improvements</li><li>Think of the next task and goal to work on</li></ul><h4>Why Do We Pair Program?</h4><p>Pair programming can by far help coders learn from each other and think of new concept and ideas along the run. Some coders may think of it as a waste of time, but it can be a good way to get to know your partner, improve communication, and practice teamwork. By far, pair programming encourages faster learning and up skilling while maintaining fewer coding mistakes.</p><h4>Retrospective Meetings</h4><p>November 7<br>Define Done: <br>What went well —Having a really strong idea on what we want to create right at the beginning of the project, we were able to complete most of our wireframes for the app, and implement the core feature of the app, which is a map.<br>What went poorly — We haven’t got much of the coding part done.<br>Acknowledgements —We’re very proud of the app logo we created during Mondays class, and the idea we came up with.</p><p>November 19<br>What went well — Had a great coding session with friends and team member. Planned out the entire framework/main features of the blog post, reiterated over the app design, and got set on an app logo.<br>What went poorly — Should spend more time on coding.<br>Acknowledgment — We are very proud of the apps theme and icon.</p><p>November 26<br>Define done — We created another blog post in addition to this to focus solely on the product design. <br>What went well — The scope and progress of both the blog post are clear and planned out. <br>What went poorly — Not working on the technical part of the project.<br>Acknowledgements — We’ve designed and scoped the blog posts out really well and we are excited to work on the technical side to make the app have more usability.</p><h4>Design</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5J20eDI3K-4FiNzNnS7jCA.png" /></figure><p>Check <a href="https://medium.com/@rinradaswift/software-product-development-7674992f3de5">this</a> blog post where we go in depth of how we use color, typography, and information hierarchy to create a great design for our product which can easily be implemented into your own designs too!</p><p>tl;dr the color theme we chose for our app was warm and calming which gives a feel of nature. Over the whole project, we used the same font family to maintain simplicity and ease for users. The information hierarchy is also set with the font size and color to set the views.</p><h4>User Testing</h4><p>From the designs we created, we were able to conduct user tests. User testing is when you put your prototype in a target users hand and see what they do. This will give insight on how to improve your UI/UX from where users get stuck, where they are confused, and how they follow through on your intended use case.</p><ul><li>How is it great?<br>Gives you a chance to improve the design of your product and the usage<br>gives other possible choices for other ways you can implement into your product.</li><li>How to conduct user tests:<br>Ask demographic questions, give context for the test, let users start navigating through the app, and don’t forget to ask follow up questions.</li></ul><p>Questions are very important, they allow us to fill in the gap of knowledge. This is why we conducted this question up:</p><p><em>“Are you a person who road travels a lot with friends and family?”</em></p><p>This lead us to letting users know the outline of what the app is about and knowing whether the user fits into our demographic or not.</p><p>After we have asked the demographic question, we went in and gave context of how we will be conducting the user test and handed over the computer to test the prototype use of the app. The users would speak out their thoughts the whole time. By the end, we asked some follow up questions such as;</p><p><em>“What are your thoughts about this app?”, “What did you like about it?”, “any feature recommendations?”, “what do you think can be more useful in the app?”.</em></p><p>Then ended it off with a kind thank you.</p><p>Thank you for joining us on our journey of creating this product! <br>A huge thanks to <a href="https://medium.com/u/4246babe7874">Rinni Swift</a> for making this project fun. 🎈<br>All feedback is accepted. 😃 Don’t forget to drop some claps! 👏👏👏</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Ff%2F50d69a%3Fas_embed%3Dtrue&amp;dntp=1&amp;display_name=Upscribe&amp;url=https%3A%2F%2Fupscri.be%2F50d69a%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/05d5fd32eda31cbd1b83287606744532/href">https://medium.com/media/05d5fd32eda31cbd1b83287606744532/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d4fbcc7dc67b" width="1" height="1" alt=""><hr><p><a href="https://uxdesign.cc/software-product-development-d4fbcc7dc67b">Software Product Development</a> was originally published in <a href="https://uxdesign.cc">UX Collective</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Helping health and fitness with tech]]></title>
            <link>https://uxdesign.cc/spd1-1-health-and-diet-cfed04bb1a2e?source=rss-ed60eee1cd58------2</link>
            <guid isPermaLink="false">https://medium.com/p/cfed04bb1a2e</guid>
            <category><![CDATA[apps]]></category>
            <category><![CDATA[ux]]></category>
            <category><![CDATA[health]]></category>
            <category><![CDATA[product-design]]></category>
            <category><![CDATA[fitness]]></category>
            <dc:creator><![CDATA[Sarin Swift]]></dc:creator>
            <pubDate>Wed, 10 Oct 2018 18:54:59 GMT</pubDate>
            <atom:updated>2018-10-21T01:52:15.240Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*0JaY1cPXOzOsI1MBpjI7MA.jpeg" /><figcaption>By <a href="https://www.everydayhealth.com/authors/genevieve-scarano/">Genevieve Scarano</a></figcaption></figure><blockquote>“Habit is a cable; we weave a thread each day, and at last we cannot break it.”―Horace Mann</blockquote><p>Ever since I was in middle school, I have always been obsessed with working out and eating healthy. Most of my friends in school would know me and my sister for that. However, when I moved overseas for college, my schedule was soon changed and I did not exercise nor be aware of the food I was eating. I had totally lacked out, and lost motivation. I came across this ted talk about adjusting your habits from small changes each day and this made me come up with an idea for an app. I want to create a platform where users can implement a really small healthy habit into their daily life.</p><h4><strong>Problems</strong></h4><p>The problem in this domain is that the many people are not educated in the field of health and nutrition. Some countries do not show the importance of keeping a healthy lifestyle through nutrition and diet. Maybe, people know <strong>what</strong> to eat, but they do not know <strong>why</strong> they should be eating like that. This creates a problem because in the era where technology has taken over many aspects of our life, we can easily get anything off the internet at ease. This convenience has changed our lifestyle mainly for the better, but it has some effects since everything is so easy to access.<br>Students or family members become a target for industries marketing unhealthy and cheap food. The food industry wants many people to get addicted to their products thus creating products without the best intentions for one’s health.</p><h4><strong>Solutions</strong></h4><p>Through all the new technology that has been invented in the past few years, we can make good use of it and enhance our perspective toward nutrition and diet. Many apps have already been created to help out people who want to have a better diet or to be able to track calories but, none of them teach users where to start. <a href="https://www.myfitnesspal.com/">MyFitnessPal</a> is a popular app that calculates calories and recommends daily calorie intake based on your weight and height. <a href="http://www.fooducate.com/">Fooducate</a>, a similar food app, gives you nutritional value of the food you search up by barcode.<br>As helpful as all these apps are, I think it would be great to have a single platform where users can browse shops, these don’t have to be restaurants, that only sell healthy and nutritious food. Or, for people who want to start a health journey, to have an app that integrates a small challenge about fitness and diet into their daily routine.</p><h4>PEST Analysis</h4><p>For laying out the foundations for my idea, I used a PEST analysis. This is a great tool to use in the world of business to help you go through all the factors. Every business moves toward profit and one single factor can prevent it from growing and improving. PEST stands for political, economic, social, and technological trends. This analysis will be used to evaluate the external factors which has influence on the health and diet domain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4ZRQV4ROB9D7no2g__J3cw.jpeg" /><figcaption>by pestleanalysis.com</figcaption></figure><p><strong>Political analysis</strong><br>- More and more companies focus toward health and diet nowadays<br>- Food and drug administration policy process<br>- Laws for selling food online<br>There’s an increasing amount of companies and businesses that are becoming more aware of health problems in society. Politics have moved towards building a more healthy society by investing in more health care programs. One of the growing concerns in America is the increasing rate of child obesity. According to the report from the <a href="http://pediatrics.aappublications.org/content/early/2018/02/22/peds.2017-3459">journal pediatrics</a>, “More than 40% (of children) are obese”. Because of the obesity rates increasing, there’s more campaigns aimed to encourage exercising and healthy eating. Some of these include lady Michelle Obama’s “<a href="https://letsmove.obamawhitehouse.archives.gov/">Let’s Move</a>” campaign and her <a href="https://www.theguardian.com/world/2014/feb/28/michelle-obama-food-campaign-obesity-political">food campaign</a>. These campaigns are hoping to help prevent adult obesity levels hitting 50% by year 2020. The app idea I have would be a good starting solution for people who want to become more healthy but don’t know where or how to start. It will allow users to slowly integrate healthy eating and exercising habits in to their daily routine.</p><p><strong>Economic Analysis</strong><br>- Unhealthy foods cost less than healthy nutritious foods<br>- People are investing money toward health more than in the past<br>- Lack of access to healthy food<br>- Consumers on food choices are based off price and quality, taste, and conveniency <br>- Personal preferences <br>- Economic growth forecast<br>In today’s society, foods that are unhealthy are being charged for a lower price and foods that are more healthy are charged for a higher price. This means consumers that don’t have enough knowledge or income to have to choose the cheaper option which is usually not good for health. In the beginning when fast food as well as junk food emerged, society valued the convenience without knowing about the impact it may have on their health. However, society is beginning to see just how unhealthy the impact of these companies are. Improve in nutrition leads to productivity and economic development. The economic costs of malnutrition is very high — several billion dollars a year in terms of lost — and this is why companies are investing more in health and nutrition.</p><p><strong>Social Analysis</strong><br>- People’s eating behavior highly depends on social influencers and what they’re eating<br>- Nowadays, social media is leaning toward creating a health concerned platform <br>- People are moving toward making their own healthy homemade meals or healthier versions of unhealthy food<br>- Food decisions are made differently depending on religion<br>- Different culture and the diet they have<br>When looking at society today, eating behaviors are very dependent on social influences and social networking. Social media technology has infiltrated our societies. One of the main side effects which is Health and fitness. From pictures of ‘goals’ body images to a variety of diets that seems to be the best for human kind. However, these impacts are not all negative and may have more of a positive impact by sharing knowledge of healthy eating and exercising. Many social influencers share the importance of eating healthy by creating posts on instagram that show their health journey. There are several instagram accounts that are only used for sharing healthy meals or sharing exercise journeys. These social media platforms are really leaning toward creating a health concerned platform.</p><p><strong>Technological Analysis</strong><br>- New food technologies fitting a specific diet<br>- Online recipes to give ideas on how you can cook<br>- Companies that have a pre cooked meal plans<br>- Food delivering companies/apps<br>- Farmers and producers are using technology such as robots, agricultural drones, and chemicals to improve growth and increase yield.<br>Today, more than ever, people have the power to create a change in the world towards a better lifestyle by inventing new technology to cure or prevent diseases. The benefits of emerging health related technologies are encouraging people to: start having healthy habits and start having easy access to knowledge for getting a better diet. When it comes to food technologies, <a href="https://soylent.com/">Soylent</a>…a company that replaces meals with a simple drink, has made getting food/nutrients more convenient than ever. But, is this product really healthy? It is your choice to decide so. Some other companies have <a href="https://www.blueapron.com/">designed meal plans</a> that can be shipped straight to your house at ease. This is all created from emerging technology that is constantly changing and improving for the future.</p><h4>Competitive Analysis</h4><p>This competitive analysis is used to compare and contrast the apps that have already been created in this field of domain. Competitive research is to collect bits of information and compare them so you have a better understanding of how you want to form your idea into an app or website. In the following image, I have compared 3 apps that are pretty similar.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A9-j4nB6ZyR44Xstslv_jA.png" /></figure><p><a href="https://www.freeletics.com/en">Freeletics</a> offers users access to workouts plans, routines, support, and explanations. They make sure that these are customized to you. You can also get a personal coach but you will have to pay monthly or yearly. <br><a href="https://sworkit.com/">Sworkit</a> allows you to easily customize workouts by type of activity. The workouts start from as short as 5 minutes.<br><a href="https://itunes.apple.com/us/app/seven-7-minute-workout/id650276551?mt=8">Seven-7 minute workout</a> only has workouts that are 7 minutes long. However, the amount of workouts you can access is very limited.</p><h4><strong>Interview Process</strong></h4><p>In my interview process, I aimed to ask unbiased questions. This is a good strategy to have in creating an effective interview and getting accurate decisions.</p><ul><li>Questions I asked: <br>How often do you eat out per week?<br>Do you like cooking homemade meals?<br>Do you have any fitness goals for yourself? If so, what are they?<br>Would you ever buy food online?</li><li>Questions I avoided:<br>Do you use any apps to help with ordering your food?<br>How often would you consider using Uber eats? And what do you think about it?<br>What is the best app in the market to help with tracking your fitness goals?<br>Is there a specific diet you are following?</li></ul><p>Feed back:<br>From my interview process with pedestrians at union square San Francisco and a couple of my friends at school, I found out that people want to get healthier. However, are not motivated to start working out and eating healthy because they feel like they have to get mentally prepared and ‘clean up’ their schedule. Although, there are a group of people that have already started their exercise routine and are loving it so far.</p><h4><strong>User Journeys</strong></h4><p>User journeys include the possible events or experiences a user might encounter when going through an app or product. This will allow you to analyze and structure your app idea to be clearer.</p><p><strong>Benefits of creating user journeys:</strong></p><ul><li>Finding edge cases of how users use your program or app</li><li>Defining keywords within your code</li><li>Designing your product for growth</li><li>Getting an insight of how users can use your product</li><li>Showing the basic steps of starting to create the product before going on further steps</li></ul><p>These user journeys are from high school/college students that have either never started a health journey, or have already started but never continued. One commonality among the three journeys is that they all want to start a healthy journey and incorporate it as a daily habit.</p><p>I’m Rinni a high school student and I wanted to start my journey on health and fitness. But I didn’t know where to start and I wasn’t very motivated to jump straight into working out. I came across this app and thought it was a great idea of how I can start off with small challenges everyday.</p><p>I’m Frenny a fitness coach and came across this fitness app one day while scrolling through the browser. I would say this app is a great way to get people going in the direction of exercising and getting them to start on small changes everyday. I have suggested it to some of my clients who have not</p><p>I’m Layla a college student who is extremely in to health and diet. But as soon as I moved out to college, I totally stopped working out and now I don’t know how to get myself as motivated as to back then. However, I downloaded this app and I have been using it for a couple weeks now. I incorporated this into my daily routine and I am starting to see a change.</p><h4>Wireframes</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_4bCiAUI7t134bNB4EnSTg.png" /><figcaption>by <a href="https://www.linkedin.com/in/sarin-swift-98224816b/">Sarin Swift</a></figcaption></figure><blockquote>“A wireframe is a visual representation of a user interface, stripped of any visual design or branding elements.” — theuxreview</blockquote><p><strong>Benefits of wire framing:</strong></p><ul><li>Gives the vision of the product you want to create</li><li>Iterates quickly and saves you time</li><li>Separates design from development</li><li>Change and update as you get feedback</li><li>Be more creative — come up with multiple designs</li></ul><p>When creating wire frames for my app, I focus on keeping the design clean and colorful, and having an easy to follow functionality. <br>I want to create an app to help users start their health journey by implementing a small change in their daily life. Users can add emojis to express how they are feeling after each challenge. And toward the end of the week, you can check your statistics.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cfed04bb1a2e" width="1" height="1" alt=""><hr><p><a href="https://uxdesign.cc/spd1-1-health-and-diet-cfed04bb1a2e">Helping health and fitness with tech</a> was originally published in <a href="https://uxdesign.cc">UX Collective</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>