<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Andrew Lundy</title>
    <description>The latest articles on Forem by Andrew Lundy (@andrewlundydev).</description>
    <link>https://forem.com/andrewlundydev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F411934%2Fd94a203d-b7b6-44cb-b30e-295ff1a1bb21.png</url>
      <title>Forem: Andrew Lundy</title>
      <link>https://forem.com/andrewlundydev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/andrewlundydev"/>
    <language>en</language>
    <item>
      <title>Software Architectural Patterns: MVVM</title>
      <dc:creator>Andrew Lundy</dc:creator>
      <pubDate>Fri, 23 Jul 2021 03:09:08 +0000</pubDate>
      <link>https://forem.com/andrewlundydev/software-architectural-patterns-mvvm-35o1</link>
      <guid>https://forem.com/andrewlundydev/software-architectural-patterns-mvvm-35o1</guid>
      <description>&lt;p&gt;Architectural patterns in software engineering describe the way a system is designed. They are reusable solutions to problems that occur widely within the domain of software engineering. One goal of architectural patterns is to separate the UI programming from the business logic. When following an architectural pattern, the code is unlikely to become 'spaghetti code,' because the programmer now has parameters that they must work within when building their program.&lt;/p&gt;

&lt;p&gt;The pattern discussed here today is the MVVM pattern. MVVM stands for Model-View-ViewModel. One of the main aims of MVVM is to separate the View from the Model, to ensure that the View is not reliant on the Model. Instead, a component called the ViewModel is used to transform the Model's data into View-usable information.&lt;/p&gt;

&lt;p&gt;MVVM was created by two engineers at Microsoft; Ken Cooper and Ted Peters. MVVM is also known as Model-View-Binder.&lt;/p&gt;

&lt;p&gt;Now to discuss how all of the components are connected.&lt;/p&gt;

&lt;h2&gt;
  
  
  Model
&lt;/h2&gt;

&lt;p&gt;Similar to MVC, the Model is responsible for handling the business logic of the program. It models the data that is pulled in from the data source, and it can also encompass things such as networking code, persistence code, parsing, extensions, and more.&lt;/p&gt;

&lt;h2&gt;
  
  
  View
&lt;/h2&gt;

&lt;p&gt;The View in MVVM is completely decoupled from the Model. The View's sole purpose is to handle the user interface elements. This is one aspect of MVVM that allows teams to rapidly build when following the design pattern. UI/UX engineers can focus on the client-facing aspect of the program, while the back-end engineers can focus on the data modeling and business logic. Views are updated by the ViewModel.&lt;/p&gt;

&lt;h2&gt;
  
  
  ViewModel
&lt;/h2&gt;

&lt;p&gt;The ViewModel is the object that transforms the Model's data into information that can be displayed on a View. An example of such a transformation would be taking a &lt;code&gt;Date&lt;/code&gt; type, and transforming it into a formatted string which would then be displayed on the View.&lt;/p&gt;

&lt;p&gt;One major difference when comparing MVC and MVVM is that the ViewModel extracts all of the data-transformation code from the Controller. When working with MVC, it's not uncommon to dump this functionality into the Controller; which leads to huge classes.&lt;/p&gt;

&lt;p&gt;Here's a visual of how the MVVM architectural pattern works:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1627009554023%2Fbhkm7LHLJ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1627009554023%2Fbhkm7LHLJ.png" alt="image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And the MVVM pattern in used in the iOS ecosystem:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1627009562701%2FHRKZzr4LP.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1627009562701%2FHRKZzr4LP.png" alt="image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  When to Use MVVM
&lt;/h2&gt;

&lt;p&gt;MVVM offers conciseness, especially when compared to MVC. Classes are more concise, the controller is more concise, and the views are more concise.&lt;/p&gt;

&lt;p&gt;Another advantage is the two-way data binding of the ViewModel and View. Because of this, anytime the Model updates the ViewModel, the View will be updated with this new data as well.&lt;/p&gt;

&lt;p&gt;It also offers a great way to design modular code, keeping components separate and decoupled. If you're on a team of designers and developers, MVVM makes it easy for the designers to focus on the UI/UX, and the developers to focus on the business logic and data. Because of the separation of the Model and View, it's hard to tell if the Model holds the correct format of data to be presented on the View. The ViewModel takes care of this and is the mediator between the Model and View that transforms the data into 'View-usable' information.&lt;/p&gt;

&lt;p&gt;Code example of MVVM: &lt;a href="https://github.com/andrew-lundy/mvvm" rel="noopener noreferrer"&gt;https://github.com/andrew-lundy/mvvm&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Further Reading
&lt;/h2&gt;

&lt;p&gt;Wikipedia MVVM: &lt;a href="https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93viewmodel" rel="noopener noreferrer"&gt;https://en.wikipedia.org/wiki/Model–view–viewmodel&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Stack Overflow, Why MVVM &amp;amp; What Are Its Core Benefits: &lt;a href="https://stackoverflow.com/a/1644955/7188134" rel="noopener noreferrer"&gt;https://stackoverflow.com/a/1644955/7188134&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Under What Conditions is the Use of MVVM Appropriate: &lt;a href="https://softwareengineering.stackexchange.com/questions/97472/under-what-conditions-is-the-use-of-mvvm-appropriate" rel="noopener noreferrer"&gt;https://softwareengineering.stackexchange.com/questions/97472/under-what-conditions-is-the-use-of-mvvm-appropriate&lt;/a&gt;&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>devjournal</category>
    </item>
    <item>
      <title>Software Architectural Patterns: MVC</title>
      <dc:creator>Andrew Lundy</dc:creator>
      <pubDate>Fri, 23 Jul 2021 03:03:56 +0000</pubDate>
      <link>https://forem.com/andrewlundydev/software-architectural-patterns-mvc-346</link>
      <guid>https://forem.com/andrewlundydev/software-architectural-patterns-mvc-346</guid>
      <description>&lt;p&gt;Architectural patterns in software engineering describe the way a system is designed. One goal of architectural patterns is to separate the UI programming from the business logic. When following an architectural pattern, the code is unlikely to become 'spaghetti code,' because the programmer now has parameters that they must work within when building their program.&lt;/p&gt;

&lt;p&gt;The pattern discussed here today is the MVC pattern. MVC stands for Model-View-Controller. This pattern is made up of three interconnected components and was originally designed for building desktop GUI applications. In today's programming world, it's used in many places such as mobile and web application development.&lt;/p&gt;

&lt;p&gt;So, what do the three interconnected components that make up the Model-View-Controller design pattern do?&lt;/p&gt;

&lt;h2&gt;
  
  
  Model
&lt;/h2&gt;

&lt;p&gt;The Model is responsible for handling the business logic of the program, and can also encompass things such as networking code, persistence code, parsing, extensions, and more.&lt;/p&gt;

&lt;h2&gt;
  
  
  View
&lt;/h2&gt;

&lt;p&gt;The View handles anything related to user interface components. These are usually reusable. In the iOS ecosystem, an example of a view would be a UIButton. Views are updated by the Controller after the Controller has been notified of what data to use by the Model.&lt;/p&gt;

&lt;h2&gt;
  
  
  Controller
&lt;/h2&gt;

&lt;p&gt;The Controller is a mediator between the Model and View. The Controller receives user input from the View, then updates the Model with the data received from the user input. After the Model is updated, it then notifies the Controller of the change, and the Controller then updates the View.&lt;/p&gt;

&lt;p&gt;Here is a visual of how this all works together:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9ymmK-vY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1627009312701/Eht6ifirz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9ymmK-vY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1627009312701/Eht6ifirz.png" alt="image.png"&gt;&lt;/a&gt;&lt;br&gt;
As you can see, the three components work together in a (somewhat) harmonious cycle. Remember, when using a design pattern, there are now parameters by which the programmer should aim to abide by. Of course, like everything in software, MVC is not perfect. One of its major flaws is that the Controller is responsible for so many things that it can quickly become a massive, cluttered mess.&lt;/p&gt;

&lt;p&gt;The main idea behind this design pattern is separating the data (model), how the data is displayed (view), and what controls and manipulates the data (controller).&lt;/p&gt;

&lt;p&gt;Example of MVC Using Swift: &lt;a href="https://github.com/andrew-lundy/mvc"&gt;https://github.com/andrew-lundy/mvc&lt;/a&gt;&lt;/p&gt;

</description>
      <category>architecture</category>
    </item>
    <item>
      <title>CS Data Structures: Fixed Array</title>
      <dc:creator>Andrew Lundy</dc:creator>
      <pubDate>Tue, 01 Jun 2021 02:02:56 +0000</pubDate>
      <link>https://forem.com/andrewlundydev/cs-data-structures-fixed-array-53c5</link>
      <guid>https://forem.com/andrewlundydev/cs-data-structures-fixed-array-53c5</guid>
      <description>&lt;h2&gt;
  
  
  Exordium
&lt;/h2&gt;

&lt;p&gt;A fixed (or fixed-size, fixed-length) array is an array that has a max amount of items. Such arrays are used when the programmer knows how many elements an array should hold - such as the number of enemy spaceships a game should display on-screen at once or the value of an 8-bit character.&lt;/p&gt;

&lt;p&gt;Some languages, such as C, Objective-C, and C++, use fixed arrays, while more modern languages use arrays that aren't set in size. In a language that uses fixed arrays, once you set the size of the array - &lt;em&gt;it does not change&lt;/em&gt;. For example, if a fixed array is initialized with 15 elements, the array can not store 16 elements. Though the array is incapable of growth, it is capable of mutation. With the first 15 elements, if the 14th element needed to be changed, it could be. If an element needs to be deleted, it can be; the fixed-size of 15 can hold less than 15 elements; it just can't hold more.&lt;/p&gt;

&lt;p&gt;Below is an array in C++ that holds 15 integers. The elements of the array are placed in a contiguous block of memory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int foo [15];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When working with fixed arrays, it's important to be precise and understand &lt;em&gt;why&lt;/em&gt; you're using this type of array. They leave room for overflow errors and are generally not a flexible data structure. That said, the good thing about these types of arrays is that they are predictable and fast. You know what to expect regarding the number of elements stored in the array and how large the array is in memory.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fixed Array Operations
&lt;/h2&gt;

&lt;p&gt;Fixed arrays should be able to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Append new elements to the end&lt;/li&gt;
&lt;li&gt;Insert new elements at the beginning and in the middle&lt;/li&gt;
&lt;li&gt;Delete elements&lt;/li&gt;
&lt;li&gt;Look up elements by index&lt;/li&gt;
&lt;li&gt;Count the size of the array&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Appending an element to the end of a fixed array is easy as long as the array isn't full. Again, the size of a fixed array does not change after it is set. This operation has a time complexity of &lt;strong&gt;&lt;em&gt;O(1)&lt;/em&gt;&lt;/strong&gt;. Another quick operation is finding an element by the index, also a &lt;strong&gt;constant time complexity&lt;/strong&gt;. To continue on the topic of time complexity, inserting and deleting are expensive with a fixed array. If an element is being inserted in the middle or beginning of a fixed array, all the elements to the right of the new element must be moved up a position in memory by 1.&lt;/p&gt;

&lt;p&gt;To add the number 5 to a fixed array:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--K23BPdt---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1622508708588/11N9Xt8VQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--K23BPdt---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1622508708588/11N9Xt8VQ.png" alt="Fixed Array Insert.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Something to note;&lt;/strong&gt; if there is code that references an object of the array using an index, and a new element is added into the middle of the array, the indexes no longer reference the correct objects.&lt;/p&gt;

&lt;p&gt;Furthermore, deleting an element from the array is the same process, but reversed. The elements are moved one position to the left instead of the right.&lt;/p&gt;

&lt;p&gt;To delete the number 5 from the same array:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eOIYc3n0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1622508729566/d47nw7ocm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eOIYc3n0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1622508729566/d47nw7ocm.png" alt="Fixed Array Delete.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Both inserting and deleting elements from a fixed array results in linear time complexity - &lt;strong&gt;&lt;em&gt;O(n)&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Build a Fixed Array
&lt;/h2&gt;

&lt;p&gt;Here, Swift is used to build a fixed array, though the concept can be used in any language.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Fundamental Properties
&lt;/h3&gt;

&lt;p&gt;The first thing to do is create the fixed array, its basic properties, and an initializer. The array needs the following properties:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;A max size to ensure it doesn't grow past what the use case needs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A default value (this will be used to add an item to the array when needed).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;An internal array (in this case, it's a &lt;a href="https://developer.apple.com/documentation/swift/array"&gt;Swift array&lt;/a&gt; ).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The count (which is updated each time an element is removed or added to the array).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Two public properties that return information. The first being the elements within the array, and the second being the length of the array. &lt;code&gt;count&lt;/code&gt; is not directly used to return the array's length (e.g., &lt;code&gt;fixedArray.count&lt;/code&gt;) because it is private. It is private because in this use case, tracking the amount of elements in an array with a counter and then reading the &lt;code&gt;count&lt;/code&gt; property is faster than directly calling the internal &lt;code&gt;count&lt;/code&gt; method on the array; which traverses through each element, then returns the number of elements in the array.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;A Fixed Array in Swift:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;struct FixedArray&amp;lt;T&amp;gt; {
    private var maxSize: Int
    private var defaultValue: T
    private var array = [T]()
    private var count = 0

    public var elements: [T] {
        return array
    }

    public var length: Int {
        return count
    }

    public init(maxSize: Int, defaultValue: T) {
        self.maxSize = maxSize
        self.defaultValue = defaultValue
        array = .init()
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The initializer sets the max amount of elements to be allowed in the array, along with the 'default value' of the array. &lt;code&gt;defaultValue&lt;/code&gt; is used to add a default object to the array when appending new objects. This will be seen in the &lt;code&gt;insert&lt;/code&gt; method.&lt;/p&gt;

&lt;p&gt;The other thing to add in the Swift implementation of a Fixed Array is a custom subscript. In Swift, you can add  &lt;a href="https://docs.swift.org/swift-book/LanguageGuide/Subscripts.html"&gt;custom subscripts&lt;/a&gt; to Structs, Classes, and Enumerations in order to access the elements of a collection, list, or sequence.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;struct FixedArray&amp;lt;T&amp;gt; {
    private var maxSize: Int
    private var defaultValue: T
    private var array = [T]()
    private var count = 0

    public var elements: [T] {
        return array
    }

    public var length: Int {
        return count
    }

    public init(maxSize: Int, defaultValue: T) {
        self.maxSize = maxSize
        self.defaultValue = defaultValue
        array = .init()
    }

    subscript(index: Int) -&amp;gt; T {
        assert(index &amp;gt;= 0)
        assert(index &amp;lt; count)
        return array[index]
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When a fixed array is initialized, it is empty. This can be seen by using the &lt;code&gt;elements&lt;/code&gt; and &lt;code&gt;length&lt;/code&gt; properties.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var array = FixedArray&amp;lt;Int&amp;gt;(maxSize: 6, defaultValue: 0)
array.elements
// []
array.length
// 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Adding Functionality to the Array
&lt;/h3&gt;

&lt;p&gt;As noted in the &lt;strong&gt;Fixed Array Operations&lt;/strong&gt; section of this article, fixed arrays should be able to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Append new elements to the end.&lt;/li&gt;
&lt;li&gt;Insert new elements at the beginning and in the middle.&lt;/li&gt;
&lt;li&gt;Delete elements.&lt;/li&gt;
&lt;li&gt;Look up elements by index.&lt;/li&gt;
&lt;li&gt;Count the size of the array.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It is important to note that any time an element is added or removed, the count variable must be updated in accordance with this action.&lt;/p&gt;

&lt;p&gt;The first custom method will be named &lt;code&gt;appendToEnd()&lt;/code&gt; and it will do just that - add an element to the end of the array. Before the method adds the element, it uses assert to make sure &lt;code&gt;count&lt;/code&gt; is less than &lt;code&gt;maxSize&lt;/code&gt; . If &lt;code&gt;count&lt;/code&gt; is greater than the total amount of allowed elements, no more elements can be added to the array. To learn more about using assert in Swift, &lt;a href="https://developer.apple.com/documentation/swift/1541112-assert"&gt;check out the official Apple Documentation&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Append to end of array
public mutating func appendToEnd(element: T) {
    assert(count &amp;lt; maxSize)
    array.append(element)
    count += 1
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, inserting elements in the middle and beginning of the array. There are a few things to keep in mind when writing this method.&lt;/p&gt;

&lt;p&gt;The array has the chance to hold different variations when adding new elements. It may be empty; it may be full; it may be half full, etc. Also, the index where an element needs to be added may be different each time the method is used.&lt;/p&gt;

&lt;p&gt;In this instance, the method checks for the following cases then proceeds to handle the insertion accordingly:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The &lt;code&gt;index&lt;/code&gt; is 0, and the &lt;code&gt;count&lt;/code&gt; property is 0. The array is empty, and the element needs to be inserted at the beginning, as the very first element in the array.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;code&gt;count&lt;/code&gt; is equal to &lt;code&gt;maxSize&lt;/code&gt; and the &lt;code&gt;index&lt;/code&gt; is 0 OR the &lt;code&gt;count&lt;/code&gt; is equal to &lt;code&gt;maxSize&lt;/code&gt; and the &lt;code&gt;index&lt;/code&gt; is not equal to 0. The array is full, and the element needs to be inserted at the beginning, or somewhere in the middle or end. This ensure that no new elements are added to the array when trying to insert them when the array is full.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;code&gt;index&lt;/code&gt; is 0, and &lt;code&gt;count&lt;/code&gt; is not equal to &lt;code&gt;maxSize&lt;/code&gt;. In this case, the requested element needs to be inserted at the beginning, shifting the current elements to the right in order to make room for the new element. This is accomplished by appending a new default element to the end of the array, traversing through the elements starting at index 1, moving through the reversed version of the elements in the array, and moving them one space to the right. Remember that the value of &lt;code&gt;index&lt;/code&gt; in this instance is 0, which ensures that the loop starts with the second element; leaving the new element in place at the 0th index of the array.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In all other cases, the array will do the same thing as case 3 above, except the loop doesn't start at index 0. In this case, the loop starts at the given value of &lt;code&gt;index&lt;/code&gt;. A visualization of this can be seen earlier in this article; under the &lt;strong&gt;Fixed Array Operations&lt;/strong&gt; section.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Insert at index of array
public mutating func insert(element: T, at index: Int) {
    assert(index &amp;gt;= 0)
    assert(index &amp;lt; maxSize)

    if index == 0 &amp;amp;&amp;amp; count == 0 {
        array.append(element)
        count += 1
    } else if count == maxSize &amp;amp;&amp;amp; index == 0 || count == maxSize &amp;amp;&amp;amp; index != 0 {
        array[index] = element
    } else if index == 0 &amp;amp;&amp;amp; count != maxSize {
        array.append(defaultValue)
        count += 1

        for i in (index+1..&amp;lt;count).reversed() {
            array[i] = array[i - 1]
        }

        array[index] = element
    } else {
        array.append(defaultValue)
        count += 1

        for i in (index..&amp;lt;count).reversed() {
            array[i] = array[i - 1]
        }

        array[index] = element

    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Fixed Array now looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;struct FixedArray&amp;lt;T&amp;gt; {
    private var maxSize: Int
    private var defaultValue: T
    private var array = [T]()
    private var count = 0

    public var elements: [T] {
        return array
    }

    public var length: Int {
        return count
    }

    public init(maxSize: Int, defaultValue: T) {
        self.maxSize = maxSize
        self.defaultValue = defaultValue
        array = .init()
    }

    // Append to end of array
    public mutating func appendToEnd(element: T) {
        assert(count &amp;lt; maxSize)
        array.append(element)
        count += 1
    }

    // Insert at index of array
    public mutating func insert(element: T, at index: Int) {
        assert(index &amp;gt;= 0)
        assert(index &amp;lt; maxSize)

        if index == 0 &amp;amp;&amp;amp; count == 0 {
            array.append(element)
            count += 1
        } else if count == maxSize &amp;amp;&amp;amp; index == 0 || count == maxSize &amp;amp;&amp;amp; index != 0 {
            array[index] = element
        } else if index == 0 &amp;amp;&amp;amp; count != maxSize {
            array.append(defaultValue)
            count += 1

            for i in (index+1..&amp;lt;count).reversed() {
                array[i] = array[i - 1]
            }

            array[index] = element
        } else {
            array.append(defaultValue)
            count += 1

            for i in (index..&amp;lt;count).reversed() {
                array[i] = array[i - 1]
            }

            array[index] = element

        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To start adding elements to the array, use either the &lt;code&gt;appendToEnd&lt;/code&gt; or &lt;code&gt;insert&lt;/code&gt; methods. Here, the integers &lt;strong&gt;1&lt;/strong&gt;, &lt;strong&gt;2&lt;/strong&gt;, and &lt;strong&gt;3&lt;/strong&gt; are added to the end of the array. Then, &lt;strong&gt;5&lt;/strong&gt; is inserted at the 3rd index, &lt;strong&gt;6&lt;/strong&gt; is inserted at the 4th index, and &lt;strong&gt;4&lt;/strong&gt; is inserted at the 3rd index. The array ends up holding &lt;code&gt;[1, 2, 3, 4, 5, 6]&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;array.appendToEnd(element: 1)
array.appendToEnd(element: 2)
array.appendToEnd(element: 3)
array.elements
// [1, 2, 3]

array.insert(element: 5, at: 3)
array.elements
// [1, 2, 3, 5]

array.insert(element: 6, at: 4)
array.elements
// [1, 2, 3, 5, 6]

array.insert(element: 4, at: 3)
array.elements
// [1, 2, 3, 4, 5, 6]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that the array can have elements added to it, there needs to be a way to remove these elements. There are three ways to remove items in a fixed array:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Remove the element at the end of the array.&lt;/li&gt;
&lt;li&gt;Remove the item based on a given index.&lt;/li&gt;
&lt;li&gt;Remove all of the items in the array.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To delete an item from the end, simply make sure that &lt;code&gt;count&lt;/code&gt; is greater than 0, use the &lt;code&gt;removeLast&lt;/code&gt; method on the array, and decrement 1 from &lt;code&gt;count&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Delete from end of array
public mutating func deleteFromEnd() {
    assert(count &amp;gt; 0)
    array.removeLast()
    count -= 1
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Removing an element based on a given index is a bit trickier. The &lt;code&gt;index&lt;/code&gt; must be less than or equal to 0, and it must also be less than the value of &lt;code&gt;count&lt;/code&gt;. After these assertions pass, &lt;code&gt;count&lt;/code&gt; is decremented by 1, the element at the given index is obtained in &lt;code&gt;result&lt;/code&gt; and the &lt;code&gt;remove&lt;/code&gt; function of the Swift array is called with &lt;code&gt;index&lt;/code&gt; as its parameter. Finally, the element that is stored in &lt;code&gt;result&lt;/code&gt; is returned.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Delete at index of array
public mutating func removeAt(index: Int) -&amp;gt; T {
    assert(index &amp;gt;= 0)
    assert(index &amp;lt; count)
    count -= 1
    let result = array[index]
    array.remove(at: index)
    return result
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Below is the usage of these two methods. The &lt;code&gt;deleteFromEnd&lt;/code&gt; method does not return the element that is removed, but the &lt;code&gt;removeAt&lt;/code&gt; method does. How they are used is up to the programmer.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;array.deleteFromEnd()
array.elements
// [1, 2, 3, 4, 5]

array.removeAt(index: 1)
// Returns 2

array.elements
// [1, 3, 4, 5]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The final 'delete' method is one that removes all of the elements from the array. The method loops through the value of &lt;code&gt;count&lt;/code&gt;, removes the last element, and decrements &lt;code&gt;count&lt;/code&gt; by 1. Once it processes the array, it then sets &lt;code&gt;count&lt;/code&gt; to 0.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Remove all elements
public mutating func removeAll() {
    for _ in 0..&amp;lt;count {
        array.removeLast()
        count -= 1
    }
    count = 0
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Again, the usage of this method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;array.removeAll()
array.elements
// []
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The methods seen here can be changed to whatever use-case the programmer may have, but they perform the basic actions that a Fixed Array should be able to perform.&lt;/p&gt;

&lt;p&gt;One thing that needs to be seen is the usage of the subscripts. It was mentioned earlier, but hasn't been used in code yet.&lt;/p&gt;

&lt;h3&gt;
  
  
  Custom Subscript in a Fixed Array
&lt;/h3&gt;

&lt;p&gt;Custom subscripts work the same way as regular subscripts. The difference is that you define what is returned when using the subscript. When an element needs to be accessed in a Fixed Array, (or other custom data type), it's accessed by using brackets - &lt;code&gt;array[element]&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;When defining a custom  &lt;a href="https://docs.swift.org/swift-book/LanguageGuide/Subscripts.html"&gt;subscript in Swift&lt;/a&gt;, a return type must be defined. This is expected, as subscripts return elements. Here is the subscript again:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;subscript(index: Int) -&amp;gt; T {
    assert(index &amp;gt;= 0)
    assert(index &amp;lt; count)
    return array[index]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Imagine that &lt;code&gt;array&lt;/code&gt; holds &lt;code&gt;[1, 2, 3, 4, 5, 6]&lt;/code&gt;. Here is how an element would be accessed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print(array.element)
// [1, 2, 3, 4, 5, 6]
let firstElement = array[0]
let fourthElement = array[3]

print(firstElement)
// 1
print(fourthElement)
// 4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The Complete Fixed Array in Swift
&lt;/h2&gt;

&lt;p&gt;That is it for the Fixed Array. This data structure can be implemented in any language, and the use case is up to the programmer. A Fixed Array can be used for situations such as tracking the number of enemies on screen in a game, creating a representation of a byte (&lt;a href="https://www.tutorialsmate.com/2020/12/memory-units-of-computer.html"&gt;bytes are a storage unit in computing&lt;/a&gt; and are made up of 8 bits. Bits are the smallest unit used for storage on a computer), or limiting the number of family members that a user can add to their family account of a subscription.&lt;/p&gt;

&lt;p&gt;Below is the complete Fixed Array in Swift, using a &lt;a href="https://docs.swift.org/swift-book/LanguageGuide/Generics.html"&gt;generic type&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;struct FixedArray&amp;lt;T&amp;gt; {
    private var maxSize: Int
    private var defaultValue: T
    private var array = [T]()
    private var count = 0

    public var elements: [T] {
        return array
    }

    public var length: Int {
        return count
    }

    public init(maxSize: Int, defaultValue: T) {
        self.maxSize = maxSize
        self.defaultValue = defaultValue
        array = .init()
    }

    // Append to end of array
    public mutating func appendToEnd(element: T) {
        assert(count &amp;lt; maxSize)
        array.append(element)
        count += 1
    }

    // Insert at index of array
    public mutating func insert(element: T, at index: Int) {
        assert(index &amp;gt;= 0)
        assert(index &amp;lt; maxSize)

        if index == 0 &amp;amp;&amp;amp; count == 0 {
            array.append(element)
            count += 1
        } else if count == maxSize &amp;amp;&amp;amp; index == 0 || count == maxSize &amp;amp;&amp;amp; index != 0 {
            array[index] = element
        } else if index == 0 &amp;amp;&amp;amp; count != maxSize {
            array.append(defaultValue)
            count += 1

            for i in (index+1..&amp;lt;count).reversed() {
                array[i] = array[i - 1]
            }

            array[index] = element
        } else {
            array.append(defaultValue)
            count += 1

            for i in (index..&amp;lt;count).reversed() {
                array[i] = array[i - 1]
            }

            array[index] = element

        }
    }

    // Delete from end of array
    public mutating func deleteFromEnd() {
        assert(count &amp;gt; 0)
        array.removeLast()
        count -= 1
    }

    // Delete at index of array
    public mutating func removeAt(index: Int) -&amp;gt; T {
        assert(index &amp;gt;= 0)
        assert(index &amp;lt; count)
        count -= 1
        let result = array[index]
        array.remove(at: index)
        return result
    }

    // Remove all elements
    public mutating func removeAll() {
        for _ in 0..&amp;lt;count {
            array.removeLast()
            count -= 1
        }
        count = 0
    }

    subscript(index: Int) -&amp;gt; T {
        assert(index &amp;gt;= 0)
        assert(index &amp;lt; count)
        return array[index]
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Thank you for reading. If you're looking for more articles about computer science and software engineering, give these a read:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; &lt;a href="https://medium.com/swift-coding/rotate-arrays-in-swift-7f223007ad6f"&gt;Rotate Arrays in Swift&lt;/a&gt;  &lt;em&gt;by Steven Curtis&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt; &lt;a href="https://andrew-lundy.medium.com/cs-data-structures-2d-array-c041032de4a7"&gt;CS Data Structures: 2D Array&lt;/a&gt; &lt;/li&gt;
&lt;li&gt; &lt;a href="https://andrew-lundy.medium.com/computer-science-recursion-6495e33144b7"&gt;Computer Science: Recursion&lt;/a&gt; &lt;/li&gt;
&lt;li&gt; &lt;a href="https://medium.com/swlh/the-concept-of-coupling-a5e910d852ae"&gt;The Concept of Coupling&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>computerscience</category>
    </item>
    <item>
      <title>An Overview of Asymptotic Notation</title>
      <dc:creator>Andrew Lundy</dc:creator>
      <pubDate>Sun, 14 Feb 2021 02:01:52 +0000</pubDate>
      <link>https://forem.com/andrewlundydev/an-overview-of-asymptotic-notation-3g1a</link>
      <guid>https://forem.com/andrewlundydev/an-overview-of-asymptotic-notation-3g1a</guid>
      <description>&lt;h1&gt;
  
  
  Exordium &amp;amp; Etymology
&lt;/h1&gt;

&lt;p&gt;Asymptotic notation describes the runtime of an algorithm based on the increasing input size of the algorithm. Asymptotic notation is important in computer science, as it helps engineers gauge the efficiency of the algorithms they write. To get a clear understanding of &lt;em&gt;asymptotic notation,&lt;/em&gt; the etymology of the two words can be seen below. (You can use the &lt;a href="http://etymonline.com/"&gt;etymonline.com&lt;/a&gt; tool to dig into the history of words).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.etymonline.com/word/asymptotic"&gt;asymptotic&lt;/a&gt; --- "having the characteristics of an asymptote," 1670s, see &lt;em&gt;asymptote&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.etymonline.com/word/asymptote"&gt;asymptote&lt;/a&gt; --- "straight line continually approaching but never meeting a curve," 1650s, from Greek &lt;em&gt;asymptotos&lt;/em&gt; "not falling together". (&lt;a href="https://en.wikipedia.org/wiki/Asymptote"&gt;Wikipedia definition&lt;/a&gt;: &lt;em&gt;an asymptote of a curve is a line such that the distance between the curve and the line approaches zero as one or both of the x or y coordinates tends to infinity&lt;/em&gt;).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.etymonline.com/word/notation"&gt;notation&lt;/a&gt; --- "explanation of a term", 1560s (this term is considered obsolete, but it actually applies here very well --- as &lt;em&gt;asymptotic notation&lt;/em&gt; is an explanation of an algorithm's runtime). "system of representing numbers or quantities by signs or symbols", 1706 (this is more literal, as you will see --- asymptotic notation describes the runtime of algorithms using symbols).&lt;/p&gt;

&lt;p&gt;Asymptotic notation is an interesting term. By examining the etymology of the two words, it's easier to understand that this notation describes an algorithm's limiting behavior as the input tends towards a particular value or infinity*.* When thinking about the runtime of algorithms, it is vital to think about and determine how long the algorithm takes and how fast a function grows with the input size.&lt;/p&gt;

&lt;p&gt;Asymptotic notation focuses on an algorithm's growth rate and simplifies the function to the most important part by getting rid of the less important factors. This means that asymptotic notation drops coefficients, constants, and low-order terms that take away from the rate of growth of the runtime. It only focuses on the parts of the algorithm that affect the growth rate, specifically the growth of &lt;em&gt;n&lt;/em&gt; --- or the input of the function.&lt;/p&gt;

&lt;p&gt;So how does one actually apply asymptotic notation? There are three main forms of asymptotic notation, which are all covered in this post:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Big-Θ notation (theta)&lt;/li&gt;
&lt;li&gt;  Big-O notation (oh)&lt;/li&gt;
&lt;li&gt;  Big-Ω notation (omega)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The different types of function growth rates are also covered down below.&lt;/p&gt;

&lt;h1&gt;
  
  
  The Big Three
&lt;/h1&gt;

&lt;h3&gt;
  
  
  Big-Theta Notation
&lt;/h3&gt;

&lt;p&gt;Big-Theta, Big-Θ, or simply Theta measures the runtime of an algorithm, or function, by bounding it between upper and lower bounds.&lt;/p&gt;

&lt;p&gt;When saying that the runtime of a function is &lt;em&gt;Θ(n)&lt;/em&gt;, it means that once &lt;em&gt;n&lt;/em&gt; gets large enough, the runtime is at least &lt;em&gt;k1 * n&lt;/em&gt; and at most &lt;em&gt;k2 * n&lt;/em&gt;. &lt;em&gt;n&lt;/em&gt; has to be bound between this lower and upper value once &lt;em&gt;n&lt;/em&gt; gets big enough.&lt;/p&gt;

&lt;p&gt;When a function uses Big-Theta Notation, it is said to be asymptotically tight bound. This means that it focuses on large inputs of &lt;em&gt;n&lt;/em&gt;, and the runtime is bound within a lower and upper value.&lt;/p&gt;

&lt;h3&gt;
  
  
  Big-O Notation
&lt;/h3&gt;

&lt;p&gt;Big-O measures the runtime of an algorithm, or function, by bounding it with an upper bound. This is like saying, "the runtime grows &lt;em&gt;at most this much&lt;/em&gt;, but it could grow more slowly."&lt;/p&gt;

&lt;p&gt;When saying that the runtime a function is &lt;em&gt;O(n)&lt;/em&gt;, it means that once &lt;em&gt;n&lt;/em&gt; gets large enough, the running time is at most &lt;em&gt;k&lt;/em&gt; &lt;em&gt; *f(n)&lt;/em&gt; for some constant &lt;em&gt;k&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Big-O notation is used for asymptotic upper bounds, as it bounds the growth of the runtime from above.&lt;/p&gt;

&lt;h3&gt;
  
  
  Big-Omega Notation
&lt;/h3&gt;

&lt;p&gt;Big-Omega, Big-Ω, or simply Omega measures the runtime of an algorithm, or function, by bounding it with a lower bound. This is like saying, "the runtime is &lt;em&gt;at least&lt;/em&gt; this much."&lt;/p&gt;

&lt;p&gt;When saying that a function's runtime is &lt;em&gt;Ω(n)&lt;/em&gt;, it means that once &lt;em&gt;n&lt;/em&gt; gets large enough, the running time is at least &lt;em&gt;k&lt;/em&gt; &lt;em&gt; *f(n)&lt;/em&gt; for some constant &lt;em&gt;k&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Big-Omega is used for asymptotic lower bounds, as it bounds the growth of the runtime from below.&lt;/p&gt;

&lt;h1&gt;
  
  
  Comparing Function Growth
&lt;/h1&gt;

&lt;p&gt;Functions grow at different rates, and it is important to know how to differentiate between these rates in order to build efficient software systems. The four different growth rates covered here are constant, linear, polynomial, and exponential.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Constant&lt;/strong&gt;: A function has &lt;em&gt;constant&lt;/em&gt; growth if its output does not change based on its input. You can identify constant functions as they have no &lt;em&gt;n&lt;/em&gt; in their expression.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Eg. 5 and 5000&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Linear&lt;/strong&gt;: A function has &lt;em&gt;linear&lt;/em&gt; growth if its output increases linearly with the size of its input. Linear functions are those where &lt;em&gt;n&lt;/em&gt; is never increased to a power, or used as a power. &lt;em&gt;n¹ is okay.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Eg. 5n and (5/3)n&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Polynomial&lt;/strong&gt;: A function has &lt;em&gt;polynomial&lt;/em&gt; growth if its output increases according to a &lt;a href="https://en.wikipedia.org/wiki/Polynomial"&gt;polynomial expression&lt;/a&gt;. Polynomial functions are those where &lt;em&gt;n&lt;/em&gt; is raised to some constant power.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Eg. 5n³ and 5n²&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Exponential&lt;/strong&gt;: A function has &lt;em&gt;exponential&lt;/em&gt; growth if its output increases according to an &lt;a href="https://www.astro.princeton.edu/~gk/.PRE-ALG-EM-FALL09/class8.pdf"&gt;exponential expression&lt;/a&gt;. Exponential functions are those where a constant is raised to some expression involving &lt;em&gt;n&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Eg. 5^n and (5/2)^n&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Keep asymptotic notation in mind when analyzing and writing algorithms. It can be looked at as a framework that guides engineers to write efficient code, and we all know how satisfying writing efficient code is. To learn more about asymptotic notation, algorithms, and computer science --- check out &lt;a href="https://www.khanacademy.org/computing/computer-science/algorithms"&gt;Khan Academy's Computer Science course&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can read &lt;a href="https://rustynailsoftware.com/blog/an-overview-of-asymptotic-notation"&gt;this post&lt;/a&gt;, and more, on my &lt;a href="https://rustynailsoftware.com/blog"&gt;blog&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>computerscience</category>
      <category>algorithms</category>
      <category>codequality</category>
    </item>
    <item>
      <title>The Concept of Coupling</title>
      <dc:creator>Andrew Lundy</dc:creator>
      <pubDate>Sun, 17 Jan 2021 22:07:32 +0000</pubDate>
      <link>https://forem.com/andrewlundydev/the-concept-of-coupling-1ipj</link>
      <guid>https://forem.com/andrewlundydev/the-concept-of-coupling-1ipj</guid>
      <description>&lt;h3&gt;
  
  
  Exordium
&lt;/h3&gt;

&lt;p&gt;In software development, coupling refers to the degree to which modules are connected. The word's etymology goes back to Latin and means 'the joining of one thing to another' or 'fastening together.' So, when thinking about coupling, think about &lt;strong&gt;&lt;em&gt;how objects are connected to one another&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Along with some other concepts, coupling was invented in 1968 as part of  &lt;a href="https://en.wikipedia.org/wiki/Larry_Constantine#structured-design"&gt;Larry Constantine&lt;/a&gt;'s 'structured design.' Structured design focuses on mapping out 'good' programming practices aimed at maintainability and adaptability.&lt;/p&gt;

&lt;h3&gt;
  
  
  Tight and Loose Coupling
&lt;/h3&gt;

&lt;p&gt;Coupling can either be tight or loose - sometimes referred to as high or low. Modules are considered &lt;em&gt;tightly coupled&lt;/em&gt; when they depend highly on each other. In other words, they have high  &lt;a href="https://www.merriam-webster.com/dictionary/interdependence"&gt;interdependence&lt;/a&gt;. Tightly coupled modules tend to have a tightly connected flow of information, leading to development issues down the road as objects become more and more reliant on each other. One way to avoid tight coupling is through dependency injection.&lt;/p&gt;

&lt;p&gt;To maintain a 'structured design,' aim to design modules that are &lt;em&gt;loosely coupled&lt;/em&gt;. This ensures that applications are being built to scale, and the objects can be reused without relying on each other.  &lt;a href="https://en.wikipedia.org/wiki/Coupling_(computer_programming)"&gt;Here's a list of the different types of coupling&lt;/a&gt; - ranked from tightest to loosest coupling.&lt;/p&gt;

&lt;h3&gt;
  
  
  Tight Coupling Example in Swift
&lt;/h3&gt;

&lt;p&gt;One example of tight coupling is seen here:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Colony {
    var queen: Bee

    init() {
        queen = QueenBee()
    }

    func formColony() {
        queen.startMating()
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, the &lt;code&gt;Colony&lt;/code&gt;  class is reliant on the &lt;code&gt;QueenBee&lt;/code&gt; class. It's reliant on the QueenBee class because it is directly connected to it within the initializer. Because of the way these two objects interact, they are considered &lt;em&gt;tightly coupled&lt;/em&gt;. If the inner-workings of the &lt;code&gt;QueenBee&lt;/code&gt; class changed, it would then change the way that the &lt;code&gt;Colony&lt;/code&gt; class operates. Coupling objects like this is inefficient because they should be able to be used independently.&lt;/p&gt;

&lt;p&gt;The tight coupling situation seen above can be fixed by adding an initializer to the &lt;code&gt;Colony&lt;/code&gt; class, passing a &lt;code&gt;Bee&lt;/code&gt; object in as a parameter, and assigning the &lt;code&gt;Queen&lt;/code&gt; variable from within the initializer.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Colony {
    var queen: Bee

    init(queen: Bee) {
        self.queen = queen
    }

    func formColony() {
        queen.startMating()
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code separates the interdependence of the objects. Enabling them to be used independently and not be affected by each other. When code is designed as described here, it adds to the software application's structural design. When thinking in terms of structural design, programmers are intentionally building software in an efficient, scalable manner.&lt;/p&gt;

&lt;p&gt;Coupling is inevitable in software development. It's the type and level of coupling that matters. In the above example, we see &lt;strong&gt;content coupling&lt;/strong&gt; - which means one object is capable of modifying the data of another object. The 'other object' being reliant on the first object. (To dive further into the types of coupling, head over to &lt;a href="https://www.geeksforgeeks.org/software-engineering-coupling-and-cohesion/"&gt;this GeeksForGeeks article&lt;/a&gt; on the subject).&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;When designing modules in software applications, it's very important to think about how they are connected. Unless modules are designed intelligently and efficiently, the application will be full of spaghetti code and fail to scale.&lt;/p&gt;

&lt;p&gt;And, what's the point in building software that doesn't scale?&lt;/p&gt;

&lt;p&gt;(Read the original article &lt;a href="https://rustynailsoftware.com/blog/the-concept-of-coupling"&gt;here&lt;/a&gt;).&lt;/p&gt;

</description>
      <category>programming</category>
      <category>codenewbie</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>Dependency Injection - What is It, and How to Use It.</title>
      <dc:creator>Andrew Lundy</dc:creator>
      <pubDate>Mon, 28 Dec 2020 06:17:03 +0000</pubDate>
      <link>https://forem.com/andrewlundydev/dependency-injection-what-is-it-and-how-to-use-it-3pno</link>
      <guid>https://forem.com/andrewlundydev/dependency-injection-what-is-it-and-how-to-use-it-3pno</guid>
      <description>&lt;h3&gt;
  
  
  What is a Dependency?
&lt;/h3&gt;

&lt;p&gt;In software engineering, there is a complex-sounding technique called &lt;strong&gt;dependency injection&lt;/strong&gt; that aims to help organize code modularly by creating objects that &lt;em&gt;depend&lt;/em&gt; on other objects. The objects that other objects depend on are called &lt;strong&gt;dependencies&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;The use of dependency injection helps solve the problem known as 'spaghetti code.' If you haven't heard of this term, it refers to software that is 'held' together by bad design and architectural planning, in which &lt;em&gt;each object is connected to one another&lt;/em&gt;. This makes codebases hard to maintain. To build software that lasts - thoughtful planning and execution are crucial, and dependency injection can help with the process of producing modular code.&lt;/p&gt;

&lt;h3&gt;
  
  
  Using Dependencies in Code
&lt;/h3&gt;

&lt;p&gt;Before we dive into injecting dependencies, I will show you a basic example of how to use one. To reiterate, a dependency is an object that other objects depend on in order to operate.&lt;/p&gt;

&lt;p&gt;In the following code, you will see a &lt;code&gt;Colony&lt;/code&gt; class with a &lt;code&gt;queen&lt;/code&gt; property, an initializer, and a &lt;code&gt;formColony&lt;/code&gt; method. There is also the &lt;code&gt;QueenBee&lt;/code&gt; class and the &lt;code&gt;Bee&lt;/code&gt; protocol.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Colony {
    var queen: Bee

    init() {
        queen = QueenBee()
    }

    func formColony() {
        queen.startMating()
    }
}

class QueenBee: Bee {
    func startMating() {
        print("Begin mating flight.")
    }
}

protocol Bee {
    func startMating()
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When an instance of &lt;code&gt;Colony&lt;/code&gt; is initialized, the &lt;code&gt;queen&lt;/code&gt; property is assigned to an instance of the &lt;code&gt;QueenBee&lt;/code&gt; class. Note that this &lt;code&gt;queen&lt;/code&gt; property can be anything that is of the &lt;code&gt;Bee&lt;/code&gt; type. &lt;/p&gt;

&lt;p&gt;The &lt;code&gt;formColony&lt;/code&gt; method calls the &lt;code&gt;queen&lt;/code&gt; object's &lt;code&gt;startMating&lt;/code&gt; method. As you can see, the &lt;code&gt;QueenBee&lt;/code&gt; class conforms to the &lt;code&gt;Bee&lt;/code&gt; protocol and will print "Begin mating flight." when the &lt;code&gt;startMating&lt;/code&gt; method is called.&lt;/p&gt;

&lt;p&gt;The dependency in this setup is the &lt;code&gt;QueenBee&lt;/code&gt; object inside the &lt;code&gt;Colony&lt;/code&gt; initializer. Since &lt;code&gt;Colony&lt;/code&gt; directly references &lt;code&gt;QueenBee&lt;/code&gt; in the initializer, it is considered &lt;em&gt;tightly coupled&lt;/em&gt; with the &lt;code&gt;QueenBee&lt;/code&gt; object. This is not good, because now &lt;code&gt;Colony&lt;/code&gt;&lt;em&gt;depends&lt;/em&gt; on &lt;code&gt;QueenBee&lt;/code&gt; to function correctly.&lt;/p&gt;

&lt;p&gt;The use of dependency injection will help avoid using dependencies as you have seen here.&lt;/p&gt;

&lt;h3&gt;
  
  
  Dependency Injection Using Swift
&lt;/h3&gt;

&lt;p&gt;Within the Swift programming language, there are a few different ways to go about dependency injection - &lt;strong&gt;initializer injection&lt;/strong&gt;, &lt;strong&gt;property injection&lt;/strong&gt;, and the lesser-used &lt;strong&gt;method injection&lt;/strong&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Initializer Injection
&lt;/h4&gt;

&lt;p&gt;When using &lt;strong&gt;initializer injection&lt;/strong&gt;, you pass the dependency object through to another object via its initializer. The usage of the dependency object (sometimes called a service) is defined within the object it's being passed to (sometimes called a client) - but the actual creation doesn't happen until it's passed through the client's initializer.&lt;/p&gt;

&lt;p&gt;To modify the previous code to adapt dependency injection using the &lt;strong&gt;initializer injection&lt;/strong&gt; method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Colony {
    var queen: Bee

    init(queen: Bee) {
        self.queen = queen
    }

    func formColony() {
        queen.startMating()
    }
}

let firstQueen = QueenBee()

let firstColony = Colony(queen: firstQueen)
firstColony.formColony()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, &lt;code&gt;Colony&lt;/code&gt; doesn't directly reference the &lt;code&gt;QueenBee&lt;/code&gt; object in its initializer. Which means the tight coupling problem has been solved, and any object of the &lt;code&gt;Bee&lt;/code&gt; type can be used with &lt;code&gt;Colony&lt;/code&gt;. The above code will print "Begin mating flight." &lt;/p&gt;

&lt;p&gt;Note that I mentioned &lt;em&gt;any&lt;/em&gt; object that is of the &lt;code&gt;Bee&lt;/code&gt; type can be passed into the initializer. This is great because you can exchange the type of bee used as the colony's queen. Of course, this wouldn't happen in the real world because bee colonies must have a queen bee - but a good example is changing the type of hive the colony lives in. I've made slight modifications to the code to show this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Colony {
    var queen: Bee

    init(queen: Bee, hiveType: Hive) {
        self.queen = queen
    }

    func formColony() {
        queen.startMating()
    }
}

let firstQueen = QueenBee()
let topBar = TopBarHive()

let firstColony = Colony(queen: firstQueen, hiveType: topBar)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can now change the type of bee as well as the type of hive used to form this colony. Another way to integrate dependency injection is through the property injection method.&lt;/p&gt;

&lt;h4&gt;
  
  
  Property Injection
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Property injection&lt;/strong&gt; is pretty much exactly what it sounds like - you pass the dependency directly through to an object's property. Here is a modified version of the &lt;code&gt;Colony&lt;/code&gt; class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Colony {
    var queen: Bee!

    func formColony() {
        queen.startMating()
    }
}

let firstQueen = QueenBee()

let firstColony = Colony()
firstColony.queen = firstQueen
firstColony.queen.startMating()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The queen is being assigned via a property, and all methods of the queen will operate as expected when called as seen. In other words, this will again print "Begin mating flight."&lt;/p&gt;

&lt;h4&gt;
  
  
  Method Injection
&lt;/h4&gt;

&lt;p&gt;A lesser-used way to integrate dependency injection is by using a setter method. Setter methods are custom methods of an object that use a parameter to set a certain property's value based on what was passed through the parameter. It works somewhat like initializer injection (in that it uses a parameter to give value a property), but you have to call it yourself after the object has been created.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Colony {
    var queen: Bee!

    func formColony() {
        queen.startMating()
    }

    func setQueenBee(_ queen: Bee) {
        self.queen = queen
    }
}

let firstQueen = QueenBee()

let firstColony = Colony()
firstColony.setQueenBee(firstQueen)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, the setter method is the &lt;code&gt;setQueenBee&lt;/code&gt; method within &lt;code&gt;Colony.&lt;/code&gt; When an object that conforms to the &lt;code&gt;bee&lt;/code&gt; protocol is passed through to that method's parameter, it will set the &lt;code&gt;bee&lt;/code&gt; property to the value of the parameter. This is another way of integrating dependency injection, but it's not the most convenient.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;That's it for dependency injection!&lt;/p&gt;

&lt;p&gt;It really isn't as scary as it sounds, and after you try it out for yourself, it will become much more instinctive. It's a simple technique that helps developers build better software by making it modular, maintainable, and scalable.&lt;/p&gt;

&lt;p&gt;Thanks for reading! If you'd like more programming content, be sure to check out the rest of the &lt;a href="https://rustynailsoftware.com/blog"&gt;Rusty Nail Software Blog&lt;/a&gt;. You can read the original post &lt;a href="https://rustynailsoftware.com/blog/what-is-dependency-injection"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Living by Your Life Principles</title>
      <dc:creator>Andrew Lundy</dc:creator>
      <pubDate>Sun, 08 Nov 2020 23:52:27 +0000</pubDate>
      <link>https://forem.com/andrewlundydev/living-by-your-life-principles-41ci</link>
      <guid>https://forem.com/andrewlundydev/living-by-your-life-principles-41ci</guid>
      <description>&lt;h1&gt;
  
  
  Exordium
&lt;/h1&gt;

&lt;p&gt;This week’s blog post is a non-technical one, focused on a ‘growth mindset’ topic. I’ll be talking about life principles, how to set them, and why it’s important to live by them. I’ll also be breaking down my eleven life principles.&lt;/p&gt;

&lt;h1&gt;
  
  
  What Are Life Principles?
&lt;/h1&gt;

&lt;p&gt;I describe life principles as principles that are truly and deeply important to you as a human. They are principles that you won’t merely budge on — and they make up the core of your character. These things are different for every single human, though some of us may share similar principles.&lt;br&gt;
I’ve seen life principles labeled as things to motivate you, ways to make you happier, or give you a better life. I disagree with these labels and believe that your life principles should be much deeper than this. So, how do you come up with principles that mean something to you?&lt;/p&gt;

&lt;h1&gt;
  
  
  How to Set Your Life Principles
&lt;/h1&gt;

&lt;p&gt;Let me start by saying there is no set number you need to aim for when setting your life principles. If you have one life principle, great. I don’t aim to sway you in choosing your principles, because again, they should mean something to you. All I can do is share with you the steps I took to set my own life principles.&lt;/p&gt;

&lt;p&gt;When setting life principles, get in a quiet place. You want to be able to really focus on what is important to you and do it without distractions. You can do this in many ways — such as closing the door to your office, wearing noise-canceling headphones in your home, or even taking a weekend trip to the woods. Whatever you need to get in a quiet place — do it.&lt;/p&gt;

&lt;p&gt;Once you’ve found a quiet place, take five minutes to meditate. Even if you’ve never meditated in your life, this will help center your mind, body, and spirit in the moment. You want to be completely intuned because these principles must come from a deep and true place.&lt;/p&gt;

&lt;p&gt;Some quick tips for those new to meditation:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Sit up straight, close your eyes, and begin breathing in a comfortable &amp;amp; natural pattern.&lt;/li&gt;
&lt;li&gt;The point of this exercise is to not think about anything but the present moment. One way to help with this is by focusing on your breathing.&lt;/li&gt;
&lt;li&gt;Literally, just breathe in and out for five minutes. When random thoughts come to your mind, be patient with yourself, and re-center your focus to your breathing.
After five minutes, open your eyes.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now that you’re centered, you can begin to think about the things that mean the most to you in life. For some, this is providing for their family. For others, this may be making an impact through their work. Each of us will have different things that come to mind and in different quantities. Next, I’ll share with you my 11 Life Principles.&lt;/p&gt;

&lt;h1&gt;
  
  
  My Life Principles
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;1. Team Human.&lt;/strong&gt;&lt;br&gt;
Team Human means doing things for the greater good of humanity. We are all one species and should work together as one. It’s that simple.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;2. Always aim to understand by breaking things down to the first principles (the fundamentals).&lt;/strong&gt;&lt;br&gt;
I approach all things with ‘first principle’ thinking. I like to know how and why things work, so breaking things down to their fundamentals helps with my overall understanding. &lt;a href="https://jamesclear.com/first-principles"&gt;Learn more about first principle thinking&lt;/a&gt; from Elon Musk.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;3. Focus on constant improvement.&lt;/strong&gt;&lt;br&gt;
Everything can be better and more efficient.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;4. Everything is learnable.&lt;/strong&gt;&lt;br&gt;
We, as humans, have the ability to learn anything we want. New things may be hard and scary, but with patience and hunger — we can learn anything.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;5. There is always a solution.&lt;/strong&gt;&lt;br&gt;
Though there are a finite amount of problems to solve, the ways those problems can be solved are infinite.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;6. Dwell, or move forward.&lt;/strong&gt;&lt;br&gt;
The idea is simple — I can dwell on my failures, the small details, and the ‘could haves’ or I can just move forward. Think of it as binary code — zeros and ones. By giving myself two options, I really only have one. I either dwell or move forward; there are no other options.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;7. Remain intellectually stimulated.&lt;/strong&gt;&lt;br&gt;
Never stop challenging the mind. Never stop connecting with other intellectuals.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;8. I make the conscious decisions of being who I am.&lt;/strong&gt;&lt;br&gt;
I’m committed to clearing the fog of life and remaining true to whom I want to be.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;9. Always over-deliver.&lt;/strong&gt;&lt;br&gt;
In everything. Big and small.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;10. Stay hungry, stay foolish.&lt;/strong&gt;&lt;br&gt;
Staying hungry means never being satisfied and always pushing yourself. Staying foolish means doing the things people say cannot be done and being humble enough to recognize that you don’t know everything.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;11. Scratch your own itch.&lt;/strong&gt;&lt;br&gt;
You have permission to learn about the things you’re interested in and try the things you want to try. If you think you can impact a certain domain, don’t be afraid to do it, even if you don’t know anything about the subject. If you think you can solve a problem, don’t be afraid to solve it. Do the things that you want to do and live on your terms.&lt;br&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Living by Your Principles
&lt;/h1&gt;

&lt;p&gt;Living by your principles makes decision making easier and your character more steadfast. When you stick to your principles, you create a compound effect related to your character. The more you practice and hold on to those principles, the stronger they become.&lt;br&gt;
Over time, you become more and more the person you want to be. This is not only a great thing for yourself, but others will know what to expect when working and interacting with you. To build your character, you must be open to new ways and remain humble.&lt;/p&gt;

&lt;p&gt;When you live by your principles, your confidence increases, as does your self-love. There is no more efficient way to make an impact other than knowing yourself deeply.&lt;br&gt;
Closing&lt;/p&gt;

&lt;p&gt;Thank you for reading this non-technical post. I hope it was a light in the darkness and that you could find some value through these words.&lt;/p&gt;

&lt;p&gt;Feel free to follow me on &lt;a href="https://twitter.com/andrewlundydev/"&gt;Twitter&lt;/a&gt;, connect with me on &lt;a href="https://linkedin.com/in/andrewlundydev/"&gt;LinkedIn&lt;/a&gt; (send a message letting me know you’re a reader), and &lt;a href="https://rustynailsoftware.com/dev-blog/"&gt;read more posts&lt;/a&gt; related to iOS Development, Freelancing, Entrepreneurship, Apiculture, and more.&lt;/p&gt;

&lt;p&gt;You can view the original posting of this blog post &lt;a href="https://rustynailsoftware.com/dev-blog/living-by-your-life-principles"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Core Location - How to Display a Human-Readable Address Using CLGeocoder</title>
      <dc:creator>Andrew Lundy</dc:creator>
      <pubDate>Sun, 06 Sep 2020 03:39:18 +0000</pubDate>
      <link>https://forem.com/andrewlundydev/core-location-how-to-display-a-human-readable-address-using-clgeocoder-lng</link>
      <guid>https://forem.com/andrewlundydev/core-location-how-to-display-a-human-readable-address-using-clgeocoder-lng</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bgZwkScL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/4cwoplqprflr3z6nb8vt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bgZwkScL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/4cwoplqprflr3z6nb8vt.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Exordium
&lt;/h3&gt;

&lt;p&gt;In a previous post, I wrote about setting up Core Location in a UIKit application. I covered adding the usage descriptions to the Info.plist file, requesting location authorization, and pulling the location from the &lt;code&gt;CLLocationManager&lt;/code&gt;. If you need some help setting up Core Location in your UIKit app, take a look at that post: &lt;a href="https://rustynailsoftware.com/dev-blog/core-location-setting-up-core-location-with-uikit"&gt;https://rustynailsoftware.com/dev-blog/core-location-setting-up-core-location-with-uikit&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In this post, I'll be going over how to implement &lt;code&gt;CLGeocoder&lt;/code&gt; - a class in Core Location that helps developers produce human-readable versions of geographic coordinates in their iOS apps. I'll also briefly cover the &lt;code&gt;CLLocation&lt;/code&gt; object, as I failed to do so in my first Core Location post. You can follow along with the code I've hosted on GitHub: &lt;a href="https://github.com/andrew-lundy/core-location-tutorial"&gt;https://github.com/andrew-lundy/core-location-tutorial&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's dive in.&lt;/p&gt;

&lt;h3&gt;
  
  
  The CLLocation Class
&lt;/h3&gt;

&lt;p&gt;An essential aspect of Core Location is the &lt;code&gt;CLLocation&lt;/code&gt; class. It's so essential that I forgot to write about it in my first Core Location series blog post. The &lt;code&gt;CLLocation&lt;/code&gt; class is an object that holds the device's location information - including the altitude and course information. The course info is the speed and direction of a device. In Core Location, you obtain the location details via the &lt;code&gt;CLLocationManager&lt;/code&gt; class. Here, I've stored the information in the &lt;code&gt;currentLocation&lt;/code&gt; variable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let locationManager = CLLocationManager()
let currentLocation = locationManager.location
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this, we have gained access to the location details and the ability to pull those details. For example, to obtain the coordinates of the location, use the location manager's &lt;code&gt;coordinate&lt;/code&gt; attribute:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let locationManager = CLLocationManager()
let currentLocation = locationManager.location
// Print the location details.
// Ex: &amp;lt;+37.78735352, -122.40822700&amp;gt; +/- 5.00m (speed - 1.99 mps / course - 1.00) @ 9/5/20, 5:13:46 PM Central Daylight Time
print(currentLocation)

let locationCoordinate = currentLocation.coordinate
// Print the coordinate value of the location as a CLLocationCoordinate2D.
// Ex: CLLocationCoordinate2D(latitude: 37.787353515625, longitude: -122.408227)
print(locationCoordinate)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Reverse-Geocoding with CLGeocoder
&lt;/h3&gt;

&lt;p&gt;As seen above, the &lt;code&gt;CLLocation&lt;/code&gt; class returns the location's information in a pretty much non-usable format. Sure, we can pull the geographic coordinates and the speed at which the device is moving. But, this information can only be useful in certain situations. What happens when we need to display the location info to users who don't want to read and convert coordinates? The answer is found in Apple's &lt;code&gt;CLGeocoder&lt;/code&gt; class.&lt;/p&gt;

&lt;p&gt;As of now, the &lt;code&gt;ViewController&lt;/code&gt; class holds the following objects and &lt;code&gt;IBOutlets&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@IBOutlet weak var changeLocationBttn: UIButton!
@IBOutlet weak var reverseGeocodeLocation: UIButton!
@IBOutlet weak var locationDataLbl: UILabel!

private var locationManager: CLLocationManager!
private var currentLocation: CLLocation!
private var geocoder: CLGeocoder!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I am going to go ahead and initialize the CLGeocoder in the viewDidLoad method of the ViewController class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;override func viewDidLoad() {
  super.viewDidLoad()
  changeLocationBttn.layer.cornerRadius = 10
  reverseGeocodeLocation.layer.cornerRadius = 10
  reverseGeocodeLocation.titleLabel?.textAlignment = .center

  locationManager = CLLocationManager()
  locationManager.delegate = self

  // Initialize the Geocoder
  geocoder = CLGeocoder()
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All of the work that the &lt;code&gt;CLGeocoder&lt;/code&gt; will be doing is going to happen in the &lt;code&gt;reverseGeocodeLocationBttnTapped&lt;/code&gt; method. The first thing we are going to do is make sure that the &lt;code&gt;currentLocation&lt;/code&gt; variable is not empty. This is set up to hold the device's location information and is given a value when the app requests authorization status. We need to make this check because there is nothing to reverse-geocode if there is no location value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@IBAction func reverseGeocodeLocationBttnTapped(_ sender: Any) {
    guard let currentLocation = self.currentLocation else {
        print("Unable to reverse-geocode location.")
        return
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To start the process of reverse-geocoding coordinates, you must call the reverseGeocodeLocation method on the &lt;code&gt;CLGeocoder&lt;/code&gt;. This method takes two parameters - a &lt;code&gt;CLLocation&lt;/code&gt; object and a &lt;code&gt;CLGeocodeCompletionHandler&lt;/code&gt;. The completion handler also has two parameters - an array of &lt;code&gt;CLPlacemark&lt;/code&gt; and an &lt;code&gt;Error&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// The method that does the reverse-geocoding.
geocoder.reverseGeocodeLocation(location: CLLocation, completionHandler: CLGeocodeCompletionHandler)

// Here is the method when in use.
geocoder.reverseGeocodeLocation(currentLocation) { (placemarks, error) in

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;CLPlacemark&lt;/code&gt; class is new, so let's take a look at it. A &lt;code&gt;CLPlacemark&lt;/code&gt;, or 'placemark,' holds the human-readable version of a coordinate and gives developers access to information such as the name of a place, the city, state, zip code, and more. You can read more about the &lt;code&gt;CLPlacemark&lt;/code&gt; class in Apple's docs: &lt;a href="https://developer.apple.com/documentation/corelocation/clplacemark"&gt;https://developer.apple.com/documentation/corelocation/clplacemark&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here are the steps we'll perform in the completion handler:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;geocoder.reverseGeocodeLocation(currentLocation) { (placemarks, error) in
    // 1
    if let error = error {
        print(error)
    }

    // 2
    guard let placemark = placemarks?.first else { return }
    print(placemark)
    // Geary &amp;amp; Powell, Geary &amp;amp; Powell, 299 Geary St, San Francisco, CA 94102, United States @ &amp;lt;+37.78735352,-122.40822700&amp;gt; +/- 100.00m, region CLCircularRegion (identifier:'&amp;lt;+37.78735636,-122.40822737&amp;gt; radius 70.65', center:&amp;lt;+37.78735636,-122.40822737&amp;gt;, radius:70.65m)

    // 3
    guard let streetNumber = placemark.subThoroughfare else { return }
    guard let streetName = placemark.thoroughfare else { return }
    guard let city = placemark.locality else { return }
    guard let state = placemark.administrativeArea else { return }
    guard let zipCode = placemark.postalCode else { return }

    // 4
    DispatchQueue.main.async {
        self.locationDataLbl.text = "\(streetNumber) \(streetName) \n \(city), \(state) \(zipCode)"
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check if the handler produces an error. If so, print it to the console. In a real app, you'd handle the error more efficiently.&lt;/p&gt;

&lt;p&gt;Use a guard statement to obtain the first placemark returned from the completion handler. For most geocoding requests, the array of placemarks should only contain one entry. I went ahead and printed the placemark data.&lt;/p&gt;

&lt;p&gt;Pull specific data out of the placemark, depending on the use case. In this instance, I've pulled the street number, street name, city, state, and zip code.&lt;/p&gt;

&lt;p&gt;Finally, I've updated the label in the app with the placemark data. Since this is changing the user interface, I have done this on the main thread using the &lt;code&gt;DispatchQueue&lt;/code&gt; class.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;reverseGeocodeLocationBttnTapped&lt;/code&gt; &lt;code&gt;IBAction&lt;/code&gt; should now look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@IBAction func reverseGeocodeLocationBttnTapped(_ sender: Any) {
    guard let currentLocation = self.currentLocation else {
        print("Unable to reverse-geocode location.")
        return
    }

    geocoder.reverseGeocodeLocation(currentLocation) { (placemarks, error) in
        if let error = error {
            print(error)
        }

        guard let placemark = placemarks?.first else { return }
        guard let streetNumber = placemark.subThoroughfare else { return }
        guard let streetName = placemark.thoroughfare else { return }
        guard let city = placemark.locality else { return }
        guard let state = placemark.administrativeArea else { return }
        guard let zipCode = placemark.postalCode else { return }

        DispatchQueue.main.async {
            self.locationDataLbl.text = "\(streetNumber) \(streetName) \n \(city), \(state) \(zipCode)"
        }
    } 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>ios</category>
      <category>swift</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Core Location - Setting up Core Location with UIKit</title>
      <dc:creator>Andrew Lundy</dc:creator>
      <pubDate>Sun, 16 Aug 2020 07:36:12 +0000</pubDate>
      <link>https://forem.com/andrewlundydev/core-location-setting-up-core-location-with-uikit-2816</link>
      <guid>https://forem.com/andrewlundydev/core-location-setting-up-core-location-with-uikit-2816</guid>
      <description>&lt;p&gt;Exordium&lt;/p&gt;

&lt;p&gt;Core Location is Apple’s native framework for obtaining a device’s location, altitude, and orientation. Core Location is also how a device interacts with iBeacon devices. All of this is very cool technology and can be utilized in amazing ways. For example, I have used Core Location to create a pothole reporting app, RoadHazard. I really view the mobile device as a way to integrate technology with day to day human life. &lt;/p&gt;

&lt;p&gt;Core Location collects data via onboard components such as Wi-Fi, GPS, Bluetooth, magnetometer, barometer, and cellular hardware. In this post, I'll show you how to initially set up Core Location in your iOS app by using a simple Storyboard-based user interface, the CLLocationManager and location simulation.&lt;/p&gt;

&lt;p&gt;You can find the code to this project on GitHub: &lt;a href="https://github.com/andrew-lundy/core-location-tutorial/tree/set-up"&gt;https://github.com/andrew-lundy/core-location-tutorial/tree/set-up&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Environment: Xcode 12, Swift 5, Deployment Target: iOS 13. (Read the blog post with photos: &lt;a href="https://rustynailsoftware.com/dev-blog/core-location-setting-up-core-location-with-uikit"&gt;https://rustynailsoftware.com/dev-blog/core-location-setting-up-core-location-with-uikit&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;The Project&lt;/p&gt;

&lt;p&gt;I’ve created a user interface that will show some location data using a UILabel. The location services will be enabled and obtained when the green button is pressed.&lt;/p&gt;

&lt;p&gt;Before you can write any Core Location code, you need to provide a reason as to why your app needs the user's location in the Info.plist file. As of iOS 13, two properties are required when requesting location access to an app - NSLocationAlwaysAndWhenInUseUsageDescription and NSLocationWhenInUseUsageDescription. The names of the keys in the Info.plist file are Privacy - Location Always and When In Use Usage Description and Privacy - Location When In Use Usage Description.&lt;/p&gt;

&lt;p&gt;Now that you’ve provided a reason to access the device location, let’s start using Core Location. In the ViewController class, you will need to import the CoreLocation framework, add a variable that holds a CLLocationManager, and extend the ViewController to be the CLLocationManagerDelegate. The CLLocationManager is the object you’ll use to request location access, start and stop location events, set the desired accuracy, and more.&lt;/p&gt;

&lt;p&gt;Next, go ahead and instantiate the CLLocationManager and set the delegate to the ViewController. &lt;/p&gt;

&lt;p&gt;Before actually using any Core Location functionality, making sure the device location services are enabled is the first thing you should do. Please note that this isn’t mandatory, but it’s good to check if your users have enabled location services so you can handle the situation accordingly. I’ve added this check to the changeLocationBttnTapped method since that’s where we’ll be launching the location services.&lt;/p&gt;

&lt;p&gt;After checking to make sure the location services are enabled, the next thing to do is to request authorization. In this case, we will be requesting 'when in use' authorization. This is exactly what it sounds like - this requests the user’s permission to use location services while the app is in use. &lt;/p&gt;

&lt;p&gt;If you run the app, an alert will pop up and ask you if you want to give the app access to the device’s location.&lt;/p&gt;

&lt;p&gt;After you choose the authorization status, you need to call the startUpdatingLocation method on the locationManager in order to begin reporting the user's location. I do this within the didChangeAuthorization method of the CLLocationManagerDelegate because an app can't report location data if it's not authorized to use the device's location services. The didChangeAuthorization method is called when the app creates the location manager and any time the authorization status of the CLLocationManager changes. &lt;/p&gt;

&lt;p&gt;The next thing to do is to check the authorizationStatus of the CLLocationManager using a switch statement. In this example, we will only be comparing the switch value to the .authorizedWhenInUse case and simply 'returning' during the default case.&lt;/p&gt;

&lt;p&gt;I’ve updated the UI to display the coordinate value of the device’s location. The coordinate type is a CLLocationCoordinate2D, and it holds the latitude and longitude of the location. In a future post, I will go through Geocoding with CLGeocoder class. Geocoding is the process of transforming the latitude and longitude into a human-readable address.&lt;/p&gt;

&lt;p&gt;As for now, that’s how you set up Core Location. It’s a pretty simple process, and the framework provides powerful features that can be used in a variety of different applications.&lt;/p&gt;

&lt;p&gt;Thank you for reading - I’ll see you in the next post!&lt;/p&gt;

</description>
      <category>ios</category>
      <category>swift</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Setting Your Git Commit Email Address</title>
      <dc:creator>Andrew Lundy</dc:creator>
      <pubDate>Sat, 08 Aug 2020 22:35:33 +0000</pubDate>
      <link>https://forem.com/andrewlundydev/setting-your-github-commit-email-address-dn6</link>
      <guid>https://forem.com/andrewlundydev/setting-your-github-commit-email-address-dn6</guid>
      <description>&lt;h1&gt;
  
  
  Exordium
&lt;/h1&gt;

&lt;p&gt;Git has a feature that displays a user’s contributions (based on commits that fall into a specific set of requirements) on their public profile. I think this is great, as it gives the public (as well as potential employers or clients) a look at your programming activity. Only public contributions are shown by default, but there is also an option to account for private ones. While working on a client project, I recently ran into an issue where the work I was pushing to GitHub was not showing up on my profile.&lt;/p&gt;

&lt;p&gt;— — —&lt;/p&gt;

&lt;h2&gt;
  
  
  A Simple Fix
&lt;/h2&gt;

&lt;p&gt;This fix does not only apply to GitHub, but can also be used for other git services. As mentioned earlier, contributions will only be displayed on your profile if they fall within a specific set of requirements. A contribution includes issues, pull requests, and commits. Usually, to add private contributions to your profile — the only thing you need to do is enable the setting. Commits have a subset of rules that they must abide by — including 1.) The email address used for the commits is associated with your GitHub account and 2.) You are a collaborator on the repository or are a member of the organization that owns the repository.&lt;/p&gt;

&lt;p&gt;After working with a client for about two weeks and using a private repo, I noticed that my commits were not being shown on my profile. I had confirmed that I was a collaborator on the repo, and assumed that my email account was attached to the commits being pushed from the command line. It turns out that I was wrong, but the fix was simple.&lt;/p&gt;

&lt;p&gt;After I added a new email to my GitHub account via the web app, I failed to change it on my local machine. It’s an easy process, and as soon as I changed the email address to one that was associated with my GitHub account — the private commits started showing up on my profile.&lt;/p&gt;

&lt;p&gt;In Terminal, you can check the current email address associated with your GitHub account by running:&lt;br&gt;
&lt;code&gt;$ git config — global user.email&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To set the email account, run:&lt;br&gt;
&lt;code&gt;$ git config — global user.email “email@example.com”&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;There you have it — a simple mistake with a simple solution.&lt;/p&gt;

</description>
      <category>git</category>
      <category>tutorial</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Set Up a Programmatic UIKit Project</title>
      <dc:creator>Andrew Lundy</dc:creator>
      <pubDate>Thu, 23 Jul 2020 17:41:34 +0000</pubDate>
      <link>https://forem.com/andrewlundydev/hey-there-b0k</link>
      <guid>https://forem.com/andrewlundydev/hey-there-b0k</guid>
      <description>&lt;h1&gt;
  
  
  Exordium
&lt;/h1&gt;

&lt;p&gt;At the time of this writing, I am working on a UIKit application for a client and wanted to share how I set up programmatic projects in Xcode. SwiftUI is quickly becoming the standard for building user interfaces for Apple's ecosystem, and I'll be updating my app RoadHazard with the framework once I'm finished with this client's project!&lt;/p&gt;

&lt;p&gt;I prefer programmatic UIs over Storyboards, and again SwiftUI brings this to a whole new level. In my experience, using a Storyboard-based app can get hectic and quite sluggish. Swift provides the same Auto Layout functionality that you'd find on a storyboard, and the transition to programmatic UIs is actually quite smooth.&lt;/p&gt;

&lt;p&gt;So, let's dive in.&lt;/p&gt;

&lt;p&gt;— — —&lt;/p&gt;

&lt;h2&gt;
  
  
  My Experience
&lt;/h2&gt;

&lt;p&gt;The first thing you'll want to do is create a new "Single View App" in Xcode. Make sure you are using the Storyboard interface.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--P4pEW_Z8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/700/1%2AFGVJAAYuWVPbBTrdDMJ04A.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--P4pEW_Z8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/700/1%2AFGVJAAYuWVPbBTrdDMJ04A.png" alt="Step One"&gt;&lt;/a&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tLVDQarF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/700/1%2AOgRfz_X-BSyNXx68CfVfQA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tLVDQarF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/700/1%2AOgRfz_X-BSyNXx68CfVfQA.png" alt="Step Two"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Secondly, go to the General Settings of your target, and under Deployment Info, you should see a dropdown option labeled Main Interface.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LjR-Qk16--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/700/1%2A7ys-FBb1BLl2umJdCuBspw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LjR-Qk16--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/700/1%2A7ys-FBb1BLl2umJdCuBspw.png" alt="Step Three"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Delete the current value.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IrsqWVwT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/700/1%2ACciVGzibTMbNUkSSftpL1g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IrsqWVwT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/700/1%2ACciVGzibTMbNUkSSftpL1g.png" alt="Step Four"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, go ahead and delete the Main.storyboard file by either Right-Clicking -&amp;gt; Delete or pressing Command (⌘) + Delete. This will produce an alert that asks you if you want to move the storyboard file to the Trash, or only remove the reference to it. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--t5L39C4P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/700/1%2AqfzDUH81LizIk7kSw-8lJg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--t5L39C4P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/700/1%2AqfzDUH81LizIk7kSw-8lJg.png" alt="Step Five"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The difference between the two is that "Move to Trash" will completely delete the file from your hard drive, and "Remove Reference" will simply remove the reference to the file in your Xcode project, but keep it on the drive. You'll want to remove the reference. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6jdEgAxT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/700/1%2AAUi3Q4y8Qjll5liLsifJ6w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6jdEgAxT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/700/1%2AAUi3Q4y8Qjll5liLsifJ6w.png" alt="Step Six"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, head over to the project's Info.plist file. Look for a key named "Application Scene Manifest" and extend it by clicking the arrow to the left of the name. This will produce two items, "Enabled Multiple Windows" and "Scene Configuration." Extend the "Scene Configuration" dictionary to reveal the "Application Session Role." Finally, extend the key named "Item 0" found in "Application Session Role." You should see a key named "Storyboard Name" - click the minus symbol next to the name to delete this key.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pdFMZ38u--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/700/1%2ATucGjLk3rSyG5IGFCqm7rw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pdFMZ38u--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/700/1%2ATucGjLk3rSyG5IGFCqm7rw.png" alt="Step Seven"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you do not remove the "Storyboard Name" key after removing the Storyboard file, and Main Interface setting of your target - the app will crash, and you will receive the following error:&lt;/p&gt;

&lt;p&gt;Terminating app due to uncaught exception 'NSInvalidArgumentException,' reason: 'Could not find a storyboard named 'Main' in bundle NSBundle.&lt;/p&gt;

&lt;p&gt;Your "Application Scene Manifest" should look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Bcova7Y0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/622/1%2AIc8Llsfif6f5U2dk_FV0ow.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Bcova7Y0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/622/1%2AIc8Llsfif6f5U2dk_FV0ow.png" alt="Step Eight"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The last thing that we're going to do will take place in the SceneDelegate file. At first, the class should contain five empty functions, and one named willConnectTo, which includes a guard let statement. We'll be working within this function. Please note that this function is called during the process when the app is starting up.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZHDTnYOu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/700/1%2AH-EeEtx8pV7llgtHrR2pVQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZHDTnYOu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/700/1%2AH-EeEtx8pV7llgtHrR2pVQ.png" alt="Step Nine"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;First, you'll want to store the scene in a variable. To do this, we just give the guard let variable a name. It's currently marked with an underscore, which means this variable doesn't have a name. This type of syntax is also seen when you want to exclude the labels when you call custom functions, amongst other uses.&lt;/p&gt;

&lt;p&gt;Go ahead and change the guard let statement to read as:&lt;br&gt;
guard let scene = (scene as? UIWindowScene) else { return }&lt;/p&gt;

&lt;p&gt;Next, you'll create the main window using the scene from the guard let statement. Remember that this scene is created during the process when the app starts up. In this case, you create the main window by initializing a UIWindow using the windowScene parameter:&lt;br&gt;
window = UIWindow(windowScene: scene)&lt;/p&gt;

&lt;p&gt;The next step is to set the root view controller of your window. This is just as it sounds - the view controller that your application considers the root of the view controller hierarchy. You do this by simply setting the rootViewController property to an instance of a view controller:&lt;br&gt;
window?.rootViewController = ViewController()&lt;/p&gt;

&lt;p&gt;The final step to getting started with a programmatic project is making the window you just created the key window of the app and showing it. You do this by calling the makeKeyAndVisible method on the window:&lt;br&gt;
window?.makeKeyAndVisible()&lt;/p&gt;

&lt;p&gt;The willConnectTo function should look like this:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gc4u2Mif--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/700/1%2AAp9xWyS0c_P97vrUQ5tq-g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gc4u2Mif--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/700/1%2AAp9xWyS0c_P97vrUQ5tq-g.png" alt="Step Ten"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I've set the ViewController's view background color to red, to show that the correct ViewController is shown when the app runs.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--C4qIHgKn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/700/1%2AcVZfjcyOizzFrZcwszcLfg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--C4qIHgKn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/700/1%2AcVZfjcyOizzFrZcwszcLfg.png" alt="Step Eleven"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;There you have it. Creating a programmatic project in Xcode is quite a simple process, and I personally prefer working with programmatic user interfaces compared to Storyboards. One is not better than the other - as they each have their pros and cons. I'd recommend learning and working with both, then deciding on which process you like more.&lt;/p&gt;

&lt;p&gt;As Apple's tech continues to advance, SwiftUI is becoming the standard way to build user interfaces for their ecosystem. That being said, I believe that there is still value in knowing UIKit as it shows you the foundation of how iOS applications are built. SwiftUI is built on top of UIKit, and you can actually integrate the two frameworks in one app.&lt;/p&gt;

&lt;p&gt;If you'd like resources on where to get started with iOS development, you can check out the projects laid out in the &lt;a href="https://www.hackingwithswift.com/read"&gt;Hacking with Swift&lt;/a&gt; series by Paul Hudson. He offers both a UIKit and SwiftUI path - 100% free. Start with some of his projects, but be sure that you branch out and build something on your own as this is where the real growth as a developer comes.&lt;/p&gt;

&lt;p&gt;Until next time - keep spreading the love, building innovative software and encouraging other humans.&lt;/p&gt;

&lt;p&gt;If you'd like, you can follow me on Twitter or LinkedIn. &lt;/p&gt;

</description>
      <category>ios</category>
      <category>swift</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How to Get Out of (or Completely Avoid) the Tutorial Trap</title>
      <dc:creator>Andrew Lundy</dc:creator>
      <pubDate>Sat, 18 Jul 2020 00:21:33 +0000</pubDate>
      <link>https://forem.com/andrewlundydev/how-to-get-out-of-or-completely-avoid-the-tutorial-trap-m27</link>
      <guid>https://forem.com/andrewlundydev/how-to-get-out-of-or-completely-avoid-the-tutorial-trap-m27</guid>
      <description>&lt;h1&gt;
  
  
  Exordium
&lt;/h1&gt;

&lt;p&gt;This post comes from my 2.5-year experience in the Tutorial Trap. This is an experience where new programmers continuously complete tutorial after tutorial, but never break out of their comfort zone to build something on their own. It can be scary to stop following the ‘pros’ and try things for yourself — but this is where the real growth happens.&lt;/p&gt;

&lt;p&gt;— — —&lt;/p&gt;

&lt;h2&gt;
  
  
  My Experience
&lt;/h2&gt;

&lt;p&gt;My experience with the Tutorial Trap, or Tutorial Hell, lasted much longer than I wish on any programmer. I’m sharing this experience to help others get out of, or avoid, this loop. During my 2.5 years in the Tutorial Trap, I dabbled in front-end, back-end, game, and mobile development. I used many sources, such as DevSlopes, Udemy, Udacity, Treehouse, Flatiron, and YouTube.&lt;/p&gt;

&lt;p&gt;I followed tens of hours of hand-holding projects, and yet, most of this information had not been retained. How could it be? I never took the training wheels of the bicycle.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test the Waters
&lt;/h2&gt;

&lt;p&gt;When you’re new to code, there are a lot of paths that you can take. I suggest ‘testing the waters’ and dipping your toes in whatever area of development that you are naturally drawn to or interested in. I started with websites — and consequently was introduced to HTML, CSS, and JavaScript. This is the path that many people take, but it’s certainly not the only way you can go. (Plus, where you start doesn’t have to be where you’ll end up — I started with web, but currently, focus more on iOS). This is called front-end web development and involves the use of JavaScript frameworks such as React, Vue, and Angular. (If you go the front-end route, you’re going to want to stick to JavaScript before learning any frameworks, as it’s crucial to understand how the underlying language works).&lt;/p&gt;

&lt;p&gt;There are other paths you can take, such as back-end development (Python, Java, Ruby, PHP), iOS (Swift) or Android (Kotlin) development, game development (C#, C++), Data Science (Python) and more.&lt;/p&gt;

&lt;p&gt;There is no ‘right’ answer here. Everybody is interested in different things, and you should really just go with what you want to do. I encourage you to test out different areas before settling on one and focusing on it for a while. Which leads me to the next point — as a starter, you don’t want to try to learn everything at once. Read more about different software development areas and get an idea as to where you’d like to start.&lt;/p&gt;

&lt;h2&gt;
  
  
  Don’t Try to Learn it All
&lt;/h2&gt;

&lt;p&gt;Once you settle on an area of software development, stick with that area of development for a while. One major thing that helped me break out of the Tutorial Trap was telling myself, “I am going to learn whatever I need to be able to build anything for the Apple ecosystem.” This was at the end of 2018, and in January 2019, I set out to accomplish this goal. I was no longer looking for all kinds of tutorials that wouldn’t provide real value to my programming skillset. I began to only consume iOS content, and specifically followed the projects from Paul Hudson’s Hacking with Swift.&lt;/p&gt;

&lt;p&gt;Within 5 months, I started building my first project on my own. It was a password management application that I called ‘Keys.’ It used a back-end powered by Google Firebase, and I was able to focus on pure iOS development during this time. The only possible way I could build an app on my own was by focusing on one area of development, and doing what it took to build my idea. This took a lot of Googling and reading documentation. I like to understand why things work the way they work and believe this is the key to a solid foundation of any topic or skill.&lt;/p&gt;

&lt;h2&gt;
  
  
  Don’t Be Afraid to Fail
&lt;/h2&gt;

&lt;p&gt;Failure is a huge part of success, and the only way to figure out what works is by understanding what doesn’t. One reason I didn’t build anything on my own was that I was simply afraid to fail. Fear will paralyze you — it’s that simple.&lt;/p&gt;

&lt;p&gt;If you’re afraid to fail, then I suggest not learning how to program. Learning how to code is a process, and you’re not going to be a pro in 30 days. You really have to learn to deal with failure and understand that you’re just learning more and adding to your skillset each time you fail.&lt;/p&gt;

&lt;p&gt;Be patient with yourself and don’t give up. Programming is hard, but you can definitely do it. When you get stuck, ask questions. Don’t be afraid to use Google. Seriously. Senior-level developers use Google every single day, and there is no shame in looking up information that you do not yet know.&lt;br&gt;
It is not important to know everything. It is important to know where to obtain the information you need.&lt;/p&gt;

&lt;p&gt;— — —&lt;/p&gt;

&lt;p&gt;The Tutorial Trap is not a pleasant experience to go through — but a lot of people do. If you’re in the Tutorial Trap, you must know that only you have the power to break out of it. It’s really a mindset, and it’s frequently driven by fear. It can certainly be scary to try to build something without the hand-holding of someone else — but it’s in this environment that you will learn and grow the most.&lt;/p&gt;

</description>
      <category>motivation</category>
      <category>career</category>
      <category>codenewbie</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
