Javatpoint Logo
Javatpoint Logo

First Swift Program

To run your first Swift program, you must have installed Xcode and Swift on your computer.

Open the Xcode playground and write down the following code:



"Hello World"

Program Explanation

      1. // This is the first Swift program also called Hello, World! Program
The above line which is started with two slashes (//) is a comment. It is totally ignored by the compiler. Comments are used to make your code understandable by other person.

      2. import Swift
The import Swift keyword is used to access all the symbols defined inside the Swift language. Without using this keyword, you can't use print statement to print anything on Xcode.

      3. print("Hello, World!")
The above line is a print function in Swift. It is used to show the output on the screen.

The "Hello World" program on Terminal

Follow the steps given below:

  1. Open the terminal
  2. Type swift and press enter. You will get a welcome message as Welcome to Apple Swift version x.x.x.
  3. Type print("Hello, World!")
  4. Press Enter


Hello, World!

Note: Unlike other programming language C, C++, Java, Python etc., Swift doesn't need to add a semicolon (;) at the end of the statement. It is optional.
You can add multiple lines in a single line by using semicolon (;) at the end of first statement.


Next TopicSwift Operators

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA