In this article you will learn |Typealias| 🚀
Introduction
Swift Typealias is used to provide a new name for an existing data type in the program. Once you create a typealias, you can use the aliased name instead of the exsisting name throughout the program.
Typealias doesn’t create a new data type, it simply provides a new name to the existing data type. It does not make any effect to your code , its just make your code more readable and easy .
Why we use it ?
The reason is why we use in a line is to just make your code clear and readable . By using them in a smart way they can be really useful in your codebase.
Typealias in Swift
You can use swift typealias with most of the types :
- Built-in types
- User define types
- Complex types
Typealias for Built in types
Instead of using String
, let us create a fake name for String
.
typealias Name = String
func insertName(name: Name) {}
insertName(name: "Mohd Yasir")
Typealias for User Define types
class Employee {}
typealias MyEmployees = [Employee]
func listEmployees(enterEmployees: MyEmployees) {}
MY LINKEDIN : linkedin.com/in/my-pro-file
Topics You May Interested IN
- Protocol : https://levelup.gitconnected.com/protocols-in-swift-7359a88248b4?source=---------8------------------&gi=b985317da979
- Enum : https://levelup.gitconnected.com/enumerations-in-swift-5dd14b4055a7
- Properties : https://medium.com/dev-genius/what-are-properties-in-swift-2ec8aba9a378
- Structure : https://medium.com/@mdcode2021/what-is-structure-in-swift-ebc22767fe1d