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 String, Int, Double, Bool types using the typealias keyword and then created variable name, num1, num2, flag variables using created alias. After that, we printed the value of variables on the console screen.
Program/Source Code:
The source code to create typealias for built-in types is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we imported a package Swift to use the print() function using the below statement,
Here, we created alias names for String, Int, Double, Bool types using the typealias keyword and then created variable name, num1, num2, flag 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