Swift Programming Tutorial: Object Oriented Programming using Classes
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.