O'Reilly logo

Swift Functional Programming - Second Edition by Dr. Fatih Nayebi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Objects

In an OOP application, objects are the runtime entities or instances that take space in memory, and more specifically, in the heap. Objects have an associated/allocated memory address to store their state and a set of functions or methods that define the suitable operations on the object state. In short, in OOP, an object encapsulates state and behavior.

To create an object, a blueprint or recipe is required, which is called a class in OOP.

The following section will explore the class concept in more detail. For now, we will define a very simple class in order to be able to talk about objects:

class User {     let name = "Constant name"     var age: Int = 0     func incrementUserAgeByOne() {         self.age += 1     } } 

In this example, name and ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required