Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Define a typealias for the whole project

In which file can I define a typealias that works in the whole project, etc.

typealias S = String
like image 984
Tomas Gudmundsson Avatar asked Jan 28 '16 15:01

Tomas Gudmundsson


People also ask

What is a Typealias?

A type alias allows you to provide a new name for an existing data type into your program. After a type alias is declared, the aliased name can be used instead of the existing type throughout the program. Type alias do not create new types. They simply provide a new name to an existing type.

How do I declare Typealias in Swift?

A typealias can be declared in Swift using the typealias keyword followed by the type you want to assign. A very simple example to understand how they can be used is by making an alias for currency, like Dollars.

What is Typealias Swift 5?

In Swift, typealias is a function that gives a new name, or an alias, to an existing type. This type can be a concrete type, like Double or a custom structure, a compound type, like tuples, or a complex closure type.


1 Answers

the typealias works the same way as variables. If you want to be global put it outside the class scope at any file.

like image 119
Ismail Avatar answered Oct 03 '22 08:10

Ismail