Swift Basic Syntax

Swift Basic Syntax

In this tutorial, we will learn the basic syntax of Swift language. We will go through the key components of a simple Swift program.

Swift Program

import Foundation

print("Hello, World!")


Hello, World!

Basic Syntax of a Swift Program

  1. import Foundation
    This line imports the Foundation framework, which provides fundamental data types, protocols, and functions for Swift programs.
  2. print("Hello, World!")
    This line uses the print function to output the string "Hello, World!" to the standard output (usually the console).

Key Points to Remember

  • All Swift statements must end with a semicolon (;), although it's often omitted and optional.
  • Swift is case-sensitive, meaning that print and Print would be considered different.
  • Comments can be added using // for single-line comments or /* ... */ for multi-line comments.
  • Swift is known for its safety features, concise syntax, and powerful features for building iOS, macOS, watchOS, and tvOS applications.