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.
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.
Program/Source Code:
The source code to create an alias of basic types is given below. The given program is compiled and executed successfully.
Output:
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.
need an explanation for this answer? contact us directly to get an explanation for this answer