Generic code enables you to write flexible, reusable functions and types that can work with any type, subject to requirements that you define. You can write code that avoids duplication and expresses its intent in a clear, abstracted manner.
Generics are one of the most powerful features of Swift, and much of the Swift standard library is built with generic code. In fact, you’ve been using generics throughout the Language Guide, even if you didn’t realize it. For example, Swift’s Array and Dictionary types are both generic collections. You can create an array that holds Int values, or an array that holds String values, or indeed an array for any other type that can be created in Swift. Similarly, you can create a dictionary to store values of any specified type, and there are no limitations on what that type can be.
The topic of generics can get very advanced, but this lesson covers the fundamentals of generics such as syntax, where you have already seen Generics, and how you can use them to improve your code over time.
This Birthday Cake exercise allows you to practice and implement Generic Functions, Generic Functions with constraints, and mutiple Generic functions in order to create an ascii cake art. It is through this excerise that you will learn to properly use generics based on a given scenario.
https://drive.google.com/file/d/1sMjocO2PWjn5vd_PASY0zT_T3XUxbd4T/view?usp=sharing