Q:

Swift program to create typealias for built-in types

belongs to collection: Swift Typealias Programs

0

Here, we will create an alias of built types using the "typealias" keyword. Then we will create variables using created alias.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program/Source Code:

The source code to create typealias for built-in types is given below. The given program is compiled and executed successfully.

// Swift program to demonstrate typealias

import Swift

typealias MyString = String
typealias MyInt    = Int
typealias MyDouble = Double
typealias MyBoolean = Bool

var name:MyString  = "Rohit Kohli"
var num1:MyInt     = 10
var num2:MyDouble  = 10.35
var flag:MyBoolean = true

print(name)
print(num1)
print(num2)
print(flag)

Output:

Rohit Kohli
10
10.35
True

...Program finished with exit code 0
Press ENTER to exit console.

Explanation:

In the above program, we imported a package Swift to use the print() function using the below statement,

import Swift

Here, we created alias names for StringIntDoubleBool types using the typealias keyword and then created variable namenum1num2flag variables using created alias. After that, we printed the value of variables on the console screen.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Swift program to create the alias of a structure... >>