Home »
Swift
Swift | Print 'Hello World' program
Swift program to print 'Hello World': Here, we are going to implement our first program in Swift programming language.
Submitted by Mahima Rao, on September 25, 2018
Swift is a language that is used to create an application for the iOS software included in Apple products. It was derived from the objective C and is an Object Oriented programming language. Let us start with the basic program of Swift i.e. Hello World.
This program will give you an idea of the syntax and how we can display the output on the screen. Like any other language, Swift also has a software i.e. XCode, where the program is run and commands are executed.
Open XCode terminal and type the following program
import Foundation
print("Hello, World!");
Hit enter key to run the program and the output will be shown.
Output
Hello, World!
Screenshot with code and the output i.e. Xcode terminal
Explanation:
Here, printf function is used to show the text quoted in " " on the output screen as in C.
Semicolon ";" is the must after every end of the command as similar in C/C++ etc.
// is used to comment in a program as depicted above.
import Foundation is a library which is used to access all the functions present that header file.
There can be many such header files that can be imported.
Whereas, "program ended with exit code: 0" at the end shows that there are no further programs to be run.
Stay connected with us to know more about Swift coding in our further tutorials.