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

Using value and reference types

The Swift Programming Language by Apple Inc. has a section on comparing structs (value type) and classes (reference type) and how to prefer one over the other. It is highly recommended to read that section to understand why we prefer one over the other. Although we touched on the topic briefly in Chapter 1, Getting Started With Functional Programming in Swift, we will explore this topic further as the distinction between reference and value types is very important in FP.

In OOP, we model real-world objects as classes and interfaces. For instance, to model an Italian restaurant with different types of pizzas, we may have a Pizzaclass and subclasses of it such as Margherita, Napoletana, or Romana. Each of these ...

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