Extensions in Swift

Extend someone else’s work — no danger

Steven Curtis
4 min readJan 20, 2020

Extensions enable you to tidy and create great code in Swift. Let’s get started!

Difficulty: Beginner | Easy | Normal | Challenging

Prerequisites:

  • Be able to produce a “Hello, World!” iOS application (guide HERE)
  • Knowledge of classes, structures and enums (guide HERE)

Terminology

class: An object defined in Swift, using pass by reference semantics (reference)

enum: A Type for a group of related values

extensions: Extensions add new functionality to a class, struct, enum or protocol

override: The process in which a subclass changes a method, property or type in the parent class

private: A level of access control that restricts the use of an entity to the enclosing declaration, and extensions of that declaration that are in the same file

struct: A value type to encapsulate complex data types

Extensions: What they are, and what they aren’t

So the idea is that you have an existing class, structure, enumeration (click the link for an explanation) and you need to extend the

--

--

No responses yet