Photo by Karl Pawlowicz on Unsplash

Initializers in swift give us the flexibility to customize how our custom classes are initialized when created. In Swift, Apple has created multiple initializers within their frameworks giving developers more options to instantiate objects with different configurations. More often than not, it will be necessary to write our own initializers for our custom classes.

Imagine we are working on an app that requires multiple labels. We are building the app programmatically and the labels require some custom styling. We might start by overriding one of the label’s designated initializer to setup our custom class.

Photo by Safar Safarov on Unsplash

Functions play a vital role in programming. They allow us to define a set of instructions into modular chunks of code to be reused making our code more clean and proned to less errors. Like any programming language, Apple has built in a plethora of functions for devs to use in their projects; there are often times we need to write our own custom functions to suit our coding needs.

If you’ve done any programming/debugging in swift, chances are you’ve used Swift’s native print() function to present data to the console. …

Photo by Alexandru Acea on Unsplash

When developing in Swift, every developer is familiar with named types. A named type, of course being, a type that can be named when declared. These types include Structs, Classes, Protocols, and Enumerations. Swift’s native types such as Strings, Ints, Arrays etc. are also named types and are Structs under the hood.

Along side with named types, Swift also has another type known as a compound type. Unlike its counterpart, compound types do not have names and include functions and tuples. Compound types can contain any combination of types associated with it wether it be named types, other compound types…

Photo by Joshua Reddekopp on Unsplash

When it comes to managing objects in Swift, Apple’s recommendation is to use a Struct over a Class where you can for easier memory management not only for the developer, but for the health of the app. Structs are value types, meaning they are allocated to the device’s heap, and do not have a reference pointer in memory and are optimized for speed.

Imagine we are working on an app that captures user information. Our data model is a simple Struct named User that takes a firstName and lastName at initializtion.

Photo by Christopher Gower on Unsplash

When it comes to programming programmatically in Swift, closures make our job easier by allowing us to set up our object’s or views right within the curly brace’s body. When the class in question is loaded into memory our objects are configured with all the attributes set by our closure.

Imagine we are building a shopping app, our data model consists of a simple struct named Product that has three properties: name, description, and price. The data will be displayed to the user via a custom view that shows details about a specific product. …

I recently worked on a project that called for an image to be inline with text for a more fluid user experience. Wondering how to solve this problem I began to contemplate wether or not I’d have to set up a bunch of constraints to have my image trailing my label in my project. While using a layout method could achieve that goal, Apple has thought ahead and gave us a solution already.

Diving into Objective-C we can utilize a handy class called NSTextattachment to hold onto our image. For the sake of this example, I will be using an…

Photo by Maxwell Nelson on Unsplash

Apple defines an enumeration as “a common type for a group of related values and enables you to work with those values in a type-safe way within your code.” We all know the saying ‘work smarter not harder’ and with Swift’s first-class type better known as an Enum, we can do just that.

One major aspect of working with UIImage is more often than not, when initialized, the image will be optional. Optionals are an amazing feature in Swift, and serve a valuable purpose, however, in some cases having to work with that caveat can become tiresome.

Imagine we decide…

Photo by Nana Dua from Pexels

I grew up in a very devout Macintosh family, playing computer games on my grandmother’s Mac. I’ve always had an interest in technology, especially Apple’s philosophy in tech and progress. When the era of smartphones came upon us, and Apple launched the first iPhone I finally knew what I wanted to grow up to be: I was going to build apps that reached many users. In 2016 I saved up enough to buy my first MacBook, and was ready to start my iOS journey. …

Herbie Dodge

iOS Developer | Swift | Looking for new opportunities 🚀

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store