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

Swift Hello World First Program

Hello World program contains three ports

  • Comments

Comments are a string of text about lines of code or swift files.

These are also ignored by the swift compiler.

It always starts with //followed by comment text

  • import

import keyword used to import namespaces that contain variables, and functions into current code. The Foundation library is a basic library that provides a utility class in Swift to import

  • print

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

Next, Open Visual Studio Editor and 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 the 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