Swift program to create an alias of basic types

Here, we are going to learn how to create an alias of basic types in Swift programming language?
Submitted by Nidhi, on May 29, 2021

Problem Solution:

Here, we will create an alias of basic types using the typealias keyword. Then we will create variables using created alias and print the value of created variables on the console screen.

Program/Source Code:

The source code to create an alias of basic types is given below. The given program is compiled and executed successfully.

// Swift program to create an alias of basic types

typealias MyIntType   = Int;
typealias MyFloatType = Float;

var num1:MyIntType   = 10;
var num2:MyFloatType = 20;

print("Num1: ",num1);
print("Num2: ",num2);

Output:

Num1:  10
Num2:  20.0

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

Explanation:

Here, we created two aliases MyIntType, MyFloatType for integer and float type. Then we created two variables using created aliases and printed the value of variables on the console screen.

Swift Basic Programs »



Related Programs



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.