Designated Initializers vs Convenience Initializers (in Swift)

Initialization in Swift Initialization is the process of preparing an instance of a class, structure, or enumeration for use. This includes setting initial values for properties and performing any necessary setup. In Swift, initializers are special methods invoked to prepare an instance. Unlike Objective-C, Swift initializers don’t return a value. Their main purpose is to... » read more

Unit Testing & Dependency Injection in Swift

Unlocking the Power of Unit Testing in Software Development In the intricate world of software development, how do we ensure that every piece of code we write functions as intended? Enter Unit Testing—a rigorous method dedicated to validating each fragment, or “unit”, of software. This approach isn’t just about verifying if a class or a... » read more

Using RESTful APIs in Swift

This article will cover how we go about using RESTful APIs in Swift: we’ll start by covering what a RESTful API actually is and move on to cover how we go from knowing we have one of these things available to actually being able to use it in our apps. The article is will not... » read more

What are Protocols? How do We Use Them?

A protocol defines a “blueprint of methods, properties, and other requirements that suit a particular task or piece of functionality”. They can give also give nominal types polymorphic behavior. In Swift, the “protocol can then be adopted by a class, structure [a struct], or enumeration [an enum] to provide an actual implementation of those requirements.... » read more

Stacks & Queues (Data Structures)

In this article, I will briefly explore Stacks and Queues. We will also look at how we can implement these data-structures in Swift, and furthermore we’ll look at the types of applications which we can use stacks and queues for. As an aside, you will often hear stacks referenced in the context of memory management,... » read more

Using Optionals in Swift

The article will aim to answer the question: what’s the best way to unwrap optionals in Swift? To answer that question we will explore what optionals actually are, and why Swift uses them. We will then consider a couple of approaches for how you might want to be unwrapping them in your code with a... » read more

Memory Management in Xcode

Let’s being with a quick refresher on how Swift and Objective-C work with memory management. Stack vs Heap It’s firstly important to know that value types (like structs) will be stored on “the stack”, whereas reference types (basically meaning classes) are dynamically managed on “the heap”. N.B. The terms “the stack” and “the heap” can... » read more

Closures in Swift

Closures are “are self-contained blocks of functionality [or chunks of code] that can be passed around and used in your code. Closures in Swift are similar to blocks in C and Objective-C and to lambdas in other programming languages.” (See my previous article on Blocks in Objective-C for more details). In Swift, functions are actually just a special case of... » read more

Polymorphism (in Swift)

What is Polymorphism? … To begin to understand this concept, it’s helpful to know that the word polymorphism comes from the Greek meaning many shapes (or forms).  In the context of Object-Oriented Programming, this means the provision of a single interface to entities of different types.   The interface provided by the objects is the same, but what’s... » read more