Swift program to create the alias of a structure

Here, we are going to learn how to create the alias of a structure in Swift programming language?
Submitted by Nidhi, on July 10, 2021

Problem Solution:

Here, we will create structure and then create the alias name of created structure using the "typealias" keyword.

Program/Source Code:

The source code to create the alias of a structure is given below. The given program is compiled and executed successfully.

// Swift program to create an alias of a structure

import Swift

struct  Person
    var id: Int
    var name: String

typealias Student = Person

var S = Student (id: 101, name: "virat")

print("Student id:   \("  )
print("Student name: \(")


Student id:   101
Student name: virat

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


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

import Swift

Here, we created a structure Person that contains two members id and name. Then we created the alias name Student of structure Person using the "typealias" keyword. After that, we created the object of structure using the Student alias and initialized and print the value of the structure.

Swift Typealias Programs »



Comments and Discussions



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© some rights reserved.