Swift Programming Tutorial: Object Oriented Programming using Classes

Arc Sosangyo
3 min readSep 7, 2021
Photo by: Sean Whelan at unsplash.com

Object-oriented programming (OOP) is an object based concept programming paradigm. The way OOP works is that an object is created, then it describes the thing and what it can do. In Swift, object is defined by using class. The description of the object is defined by: initialization, properties, methods, and inheritance.

This article is part of my Swift Programming Tutorial series.

For this tutorial, we’re going to create an object containing different superpowers.

Properties

A property is either a variable or constant inside a class.

E.g.

class SuperPowers {
let powerOne: String = "Super Strength"
let powerTwo: String = "Super Speed"
let powerThree: String = "Flight"
var numberOfPowers: Int = 3
}
var showPower = SuperPowers() print(showPower.powerThree)

The output will be:

Flight

In our above example, we use properties to declare different types of superpowers. Then in order to show one of those superpowers, we call the SuperPowers class in a variable then print one of its properties.

Methods

--

--

Arc Sosangyo
Arc Sosangyo

Written by Arc Sosangyo

Arc is an iOS developer and app publisher, a former IT manager who transitioned to iOS engineering, and a big fan of coding, science, history, and philosophy.