Hello World is an First program that explains how to write a program, compile and run the program in Swift.

Swift Hello World First Program

Hello World program contains three ports

  • Comments

Comments are string of text about lines of code or swift file.

These also ignored by swift compiler.

It always starts with //followed by comment text

  • import

import keyword used to import namespaces that contains variables, functions into currect code. Foundation library is a basic library that provides utilities class in Swift to import

  • print

print is output function that print the string to the console.

Next,First Open Visual Studio Editor, Create a Hello.swift

Swift code extension is .swift

Hello.swift:


// Hello.swift
// Hello World program in Swift
import Foundation;

print("Hello World W3schools.io!");

Compile and Run swift program

Compile the code using swiftc compiler

swiftc Hello.swift

It compiles the code and creates an executable file Hello.

You can run the code using

in Windows

Hello

In Linux or Mac

./Hello