Typealias for custom naming
📖 Scenario: Imagine you are creating a simple app that tracks distances in kilometers. You want to make your code easier to read by giving a custom name to the Double type that represents distances.
🎯 Goal: You will create a typealias called Distance for Double, then use it to declare variables and print their values.
📋 What You'll Learn
Create a typealias named
Distance for the Double typeDeclare a variable called
homeToSchool of type Distance with the value 3.5Declare a variable called
schoolToPark of type Distance with the value 1.2Calculate the total distance by adding
homeToSchool and schoolToParkPrint the total distance using
print💡 Why This Matters
🌍 Real World
Using <code>typealias</code> helps make code easier to read and understand by giving meaningful names to types, especially in apps dealing with measurements or complex data.
💼 Career
Many software jobs require writing clear and maintainable code. Knowing how to use <code>typealias</code> is a simple way to improve code clarity and teamwork.
Progress0 / 4 steps